#P16913. [JLCPC 2026] Map1e
[JLCPC 2026] Map1e
Problem Description
Given a positive integer , define the repunit number as the number consisting of digits of , that is, .
Please find the largest positive integer such that is a divisor of , and output .
Note that is a divisor of every positive integer, so the answer is at least .
Input Format
The first line contains an integer (), representing the number of test cases. Then follow blocks, each describing one test case:
- The first line contains a positive integer (, where denotes the number of decimal digits of ; it is guaranteed that has no leading zeros).
It is guaranteed that .
Output Format
For each test case, output one positive integer per line.
3
1221
99
7
3
2
1
Hint
In the first sample, , so is a divisor of . is not a divisor of , so the answer is .
In the second sample, , so is a divisor of . , so the answer is .
In the third sample, is not a multiple of , so the answer is .
Translated by ChatGPT 5