The Python code returns the smallest palindrome P given an integer p (num in the code).
import sys def is_palindrome(num): if (num % 10 == 0): return False; r = 0; while (r < num) : r = 10 * r + num % 10; num /= 10; return (num == r) or (num == r / 10); num = input("Enter a positive integer:"); k=0; multiple=12;#initialisation: any non-palindrome while (not is_palindrome(multiple)): k+=1; multiple=k*num; print(str(num)+"*"+str(k)+"="+str(multiple));
Hi Function,
Your formula doesn't work for odd numbers. The digit in the middle will have the number (n+1)/2, and you will have a sum member 2*x_i*10^{(n-1)/2} instead of x_i*10^{(n-1)/2}.
I made a similar decomposition, but could not get any conclusion from it.