Number Conversion
One of the first lessons for computer science students is representing natural numbers in the binary numeral system (base ). This system uses only two digits, and .
In everyday life, we use the decimal system (base ) for convenience, which uses ten digits, from to . Generally, we could use any numbering system. For example, computer scientists often use systems based on or . In a numbering system with base , digits are used with values from to .
Suppose a natural number is given, written in the decimal system. To convert it to the corresponding representation in the base system, we successively divide by until we reach a quotient smaller than . The representation of in the base system is formed by the final quotient (as the first digit) followed by the remainders of the preceding divisions. For example, for and :
That is, (the number in the decimal system is equal to in the octal system: ). A student made the following observation: by applying the above rule of converting natural numbers to another numbering system, in some cases, all the digits of the number are the same in the new representation. For example, .
Problem
Write a program in one of the IOI languages which, when given a number in its decimal representation, finds the smallest base such that in the representation of in base , all the digits are the same.
Input
The input files named numbase.in are text files with the following structure: The first line contains a natural number , the number of numbers to follow. lines follow, each containing a natural number where ).
Output
The output files named numbase.out are text files with the following structure: They contain lines, each containing only one integer where . must be the minimum base so that the representation of the number has all its digits the same.
Example of Input - Output Files:
STDIN (numbase.in)
5
7
42
63
2
630
STDOUT (numbase.out)
2
4
2
3
29
Scorring:
In % of the test cases, will be .
In % of the test cases, will be .
In % of the test cases, will be .
Attention!: For % of the test cases, you will need 64-bit integers (long long or int64_t in GNU C/C++, Int64 in Free Pascal).
Formatting: In the output, each line terminates with a newline
character.
Maximum execution time: 1 sec.
Maximum available memory: 64 MB.
Comments