All submissions for this problem are available.
A positive integer is said to be a palindrome with respect to base b, if its representation in base b reads the same from left to right as from right to left. Palindromes are formed as follows:
Given a number, reverse its digits and add the resulting number to the original number. If the result isn't a palindrome, repeat the process. For example, start with 87 base 10. Applying this process, we obtain:
87 + 78 = 165
165 + 561 = 726
726 + 627 = 1353
1353 + 3531 = 4884, a palindrome
Whether all numbers eventually become palindromes under this process is unproved, but all base 10 numbers less than 10,000 have been tested. Every one becomes a palindrome in a relatively small number of steps (of the 900 3-digit numbers, 90 are palindromes to start with and 735 of the remainder take fewer than 5 reversals and additions to yield a palindrome). Except, that is, for 196. Although no proof exists that it will not produce a palindrome, this number has been carried through to produce a 2 million-digit number without producing a palindrome.
The first line of input file contains positive integer t – the amount of test cases. Next t lines contain a positive integer and its base. Bases will be in the range 10 – 36.
Print the palindrome produced. If no palindrome is produced after 10 additions, print the word “none” and the last sum.
- 10 ≤ base ≤ 36
- 1 ≤ t ≤ 10
5 420, 13 46894, 10 NITUK, 35 CODEGURU, 36 PRODAYA, 35 Output:
444 NONE, 1317544822 NONE, L6SFFT6K TLRCSCRLT BH8888HB
|Time Limit:||5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, PERL, FORT, WSPC, PRLG, LISP sbcl, LISP clisp, JS, PERL6, TEXT|
Fetching successful submissions
If you are still having problems, see a sample solution here.