Beautiful Numbers (Small)
Time limit5sMemory limit512 MB
For each N, find a base B > 1 where N is written with only the digit 1, preferring the base with the most 1 digits.
- Level
Easy3 of 10
- Topics
- Math, Brute force, Number theory, Implementation
- Solved
- No attempts yet
Problem
Call a number beautiful if it is written with the digit 1 repeated one or more times. Not every number is beautiful in base 10, but any positive integer can be made beautiful by writing it in another base.
You are given an integer . Find a base (with ) such that every digit of written in base is 1. If several bases work, choose the one that gives the most 1 digits.
Input
The first line contains the number of test cases . Each of the following lines contains one integer .
Limits
Output
For each test case, print one line of the form Case #x: y, where is the test case number starting from 1 and is the base described above.
Hint
For the best answer is 11 in base 2, so is 2.
For the best answer is 111 in base 3, so is 3. The number 13 is also 11 in base 12, but that form has fewer 1 digits.