C-PROM 2014 (PROBLEM 9 :PALINDROME)



PROBLEM 9 : PALINDROME


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.

Input
The first line of the input contains an integer N (1 ≤ N ≤ 5), the number of test cases. Following the first line are the test cases. Each line of a test case contains an integer number. All test cases are non negative integer numbers.
The input must be read from standard input.

Output
Print the palindrome number produced and followed by for how many attempts the palindrome number is found. If no palindrome is produced after 10 attempts, print the last sum and the word “none”.

Sample Input
Sample Output
5
87
196
1689
46785
46894

4884;Palindrome;5
10755470;None
56265;Palindrome;5
1552551;Palindrome;4
664272356;None




Problem Setter : Jamal Othman, UiTM Pulau Pinang


Share this

Related Posts

Previous
Next Post »