#P1643. 完美数
完美数
Description
During an expedition, the archaeologist Xiaoxing accidentally fell into an abyss and traveled to a mysterious desert. Many things here are beyond his understanding, such as buildings floating in the air and all kinds of strange animals.
In the center of the desert, Xiaoxing found a huge temple-like structure. To escape this place, he decided to explore it.
As he approached the temple gate, a human-faced lion suddenly leaped out (not the Sphinx)! It roared:
"I am the guardian here. To pass, you must answer my series of questions; otherwise, I will eat you."
The human-faced lion told Xiaoxing that the questions always follow this pattern: What is the -th smallest palindrome greater than ?
Xiaoxing thought the problem did not seem difficult, so the Q&A began.
"What is the 1st smallest palindrome greater than ?" "."
"What is the 2nd smallest palindrome greater than ?" "."
"What is the 2nd smallest palindrome greater than ?" "."
"Then what is the 2,339,587-th smallest palindrome greater than ?" "*(•%(∗•—#•#¥∗—%(∗—%"
To avoid being eaten by the guardian, Xiaoxing opened his laptop to seek help, and he unexpectedly found you through the network (Netcom? Telecom? Universe-com?). So this problem is entrusted to you!
Input Format
The input contains multiple queries.
The first line contains an integer , the total number of queries.
Each query consists of two lines: the first line contains , and the second line contains , asking for the -th smallest palindrome strictly greater than .
Output Format
For each query, output one line containing the answer.
3
1
1
17
2
98
2
2
33
101
Hint
Constraints:
- 20% of the testdata satisfies , .
- 30% of the testdata satisfies and the answer is no greater than .
- 100% of the testdata satisfies and the answer is no greater than , and .
Translated by ChatGPT 5
京公网安备 11011102002149号