Galactic Bonus
Time limit0.4sMemory limit8 MB
For each age up to 2^64 - 1, find the smallest base in which the number has exactly two digits equal to 1 and all other digits 0.
- Level
Medium6 of 10
- Topics
- Math, Binary search, Number theory
- Solved
- No attempts yet
Problem
The Parliament of the Galactic Federation is losing popularity, so it decided to pay a bonus to citizens whose age in years is a round number. Years have the same length on all planets thanks to the Standard Galactic Calendar.
Some species use different bases in their number systems, so critics said "round numbers" cannot be defined. After long debate, the Parliament ruled that an age is round if it can be written as in some base . That means exactly two digits are 1, and all other digits are 0. The bonus is the smallest base in which is round.
Once the law took effect, the Parliament needed a fast way to compute the bonuses. Given the number of citizens and each citizen's age , find the lowest base in which each age is round.
Input
The first line contains an integer , the number of citizens. Each of the next lines contains one integer age .
Output
Print lines. Line contains the lowest base in which is a round number.
Constraints
for every .
Hints
Some numbers are round in several bases. For example, 36 is also round in base 3, since . The answer must still be the lowest base, so the answer for 36 is 2.