#P16593. [GKS 2016 #E] Beautiful Numbers

[GKS 2016 #E] Beautiful Numbers

Problem Description

We consider a number to be beautiful if it consists only of the digit 11 repeated one or more times. Not all numbers are beautiful, but we can make any base 1010 positive integer beautiful by writing it in another base.

Given an integer NN, can you find a base BB (with B>1B > 1) to write it in such that all of its digits become 11? If there are multiple bases that satisfy this property, choose the one that maximizes the number of 11 digits.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of one line with an integer NN.

Output Format

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 11) and yy is the base described in the problem statement.

2
3
13
2
3

Hint

In case #11, the optimal solution is to write 33 as 1111 in base 22.

In case #22, the optimal solution is to write 1313 as 111111 in base 33. Note that we could also write 1313 as 1111 in base 1212 or as 11 in base 1313, but neither of those representations has as many 11s.

Limits

1T1001 \le T \le 100.

Small dataset (Test set 1 - Visible)

3N10003 \le N \le 1000.

Large dataset (Test set 2 - Hidden)

3N10183 \le N \le 10^{18}.