All submissions for this problem are available.
Johnny has figured out that there are some numbers which have an interesting property: they are the same when read from left to right, and from right to left. For example, 5115 and 929 are such numbers, while 31 and 125 are not. Johnny calls such numbers palindromic numbers.
After a while, Johnny has realized that his definition of palindromic numbers is not really precise. Whether a number is palindromic or not depends on the base in which the number is written. For example, 21 is not palindromic in base 10 but it is palindromic in base 2 (because 21 = 101012).
Johnny finds it interesting that any number becomes palindromic when it is written in an appropriate base.
Given a number N, write a program to help Johnny compute the smallest base B such that N is palindromic when written in base B.
The first line contains t, the number of test cases (about 1000). Then t test cases follow.
Each test case consists of a number N written in one line (1 <= N <= 1010).
For each given number N, print a line containing the smallest base B such that N is palindromic in base B.
Input: 3 1 4 21 Output: 2 3 2
|Time Limit:||0.400922 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.