All submissions for this problem are available.
A simple recursive method to generate a numeric palindrome from any
number is to reverse its digits and add it to the original. If the sum is not a
palindrome (which means, it is not the same number from left to right and right
to left), repeat this procedure. For example for 195:
195 + 951 = 786
786 + 687 = 1473
1473 + 3741 = 5214
5214 + 4125 = 9339
this particular case the palindrome 9339 appeared after 4th addition. This
method leads to palindromes in a few step for almost all of the integers. But
there are interesting exceptions. 196 is the first number for which no
palindrome has been found. It is not proven though, that there is no such a
task is to write a program that gives the resulting palindrome and the number of
iterations (additions) to compute it. All tests data in this problem will have
an answer, will be computable with less than 1000 iterations (additions), which
will yield a palindrome that is not greater than 4,294,967,295.
The first line will have a number N (0<N<=100) with the number of test
cases, the next N lines will each have a number P to compute its palindrome.
For each of the N numbers you will have to write a line with the minimum
number of iterations (additions) to get to the palindrome and the resulting
palindrome separated by one space.
|Time Limit:||1.25 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, 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, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.