#P10702. [SNCPC2024] 下棋
[SNCPC2024] 下棋
Problem Description
LNC likes numbers whose product of all digits in base is a divisor of the number itself. He calls such numbers LNC numbers. For example:
When , is an LNC number because .
When , is an LNC number because after converting to decimal, , and .
When , is not an LNC number because after converting to decimal, , and is not a divisor of .
LNC is playing a game with LJJ. LJJ gives chess pieces, and then LNC chooses an integer (). After that, they take turns removing some chess pieces, and the number of pieces removed each time must be an LNC number in base . LNC moves first, and whoever takes the last pieces wins. Both players are extremely smart, so they will both play with the best strategy.
LJJ thinks this game is unfair. They played a total of games. For each given , he wants to know the smallest such that LNC, as the first player, is guaranteed to win.
Input Format
The first line contains a positive integer (), indicating the number of test cases.
The next lines each contain a positive integer (), representing the number given by LJJ.
Output Format
Output lines, each containing a positive integer , the smallest such that for that query, LNC (the first player) is guaranteed to win.
3
9
5
10
2
2
3
Hint
When , LNC can choose . .
LNC first removes . Then . LJJ can only remove , and then LNC removes the last and wins.
Also, since cannot be any smaller, the final answer is .
Translated by ChatGPT 5