If we take a, reverse and add, + = 121, which is palindromic.
Not all numbers produce palindromes so quickly. For example,
349 + 943 = 1292,
1292 + 2921 = 4213
4213 + 3124 = 7337
That's, 349 took three iterations to arrive at a palindrome.
although no one has proved it yet, it Is thought this some numbers, like 196, never produce a palindrome. A number that never forms a palindrome through the reverse and add process is called a lychrel number. Due to the theoretical nature of these numbers, and for the purpose of this problem, we shall assume that a number is Lych Rel until proven otherwise. In addition is given that for every number below Ten-thousand, it'll either (i) become a palindrome in less than fi Fty iterations, or, (ii) No one, with all of the computing power that exists, have managed so far to map it to a palindrome. In fact, 10677 are the first number to being shown to require over fifty iterations before producing a palindrome:46687315966 84224866951378664 (iterations, 28-digits).
Surprisingly, there is palindromic numbers that is themselves lychrel numbers; The first example is 4994.
How many Lychrel numbers is there below Ten-thousand?
Note:wording was modified slightly on April emphasise the theoretical nature of lychrel numbers.
The number of palindrome can not be obtained by the above method in 10000 or less.
#include <iostream> #include <string>using namespace std;string num2str (int n) {string ans = ""; while (n) {int a = n 10;char B = A + ' 0 '; ans = b + ans;n/= 10;} return ans;} String Strplus (String A, string b) {int len = a.length (); int flag = 0;string ans = ""; for (int i = len-1; I >= 0; i--) {int tmp = A[i] + b[i]-' 0 '-' 0 ' + flag;flag = tmp/10;tmp = tmp% 10;char p = tmp + ' 0 '; ans = p + ans;} if (flag = = 1) ans = ' 1 ' + Ans;return ans;} BOOL Pali (string a) {for (int i = 0; i < a.length ()/2; i++) {if (A[i]! = A[a.length ()-1-i]) return false;} return true;} BOOL Islychrel (int n) {string A, B;a = NUM2STR (n); B.assign (A.rbegin (), A.rend ()); for (int i = 1; i <=; i++) {a = STRPL US (A, B), if (Pali (a)) return False;b.assign (A.rbegin (), A.rend ());} return true;} int main () {int count = 0;for (int i = 1; I <= 10000; i++) {if (Islychrel (i)) count++;} cout << Count << endl;system ("pause"); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Project Euler:problem Lychrel Numbers