Lychrel Numbers
A Lychrel number is a number that never forms a palindrome through the reverse-and-add process. Working with the assumption that a number is Lychrel if it has not produced a palindrome within 50 it...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
If we take $47$, reverse and add, $47 + 74 = 121$, which is palindromic.
Not all numbers produce palindromes so quickly. For example, \begin{align*} 349 + 943 &= 1292\\ 1292 + 2921 &= 4213\\ 4213 + 3124 &= 7337 \end{align*} That is, $349$ took three iterations to arrive at a palindrome.
Although no one has proved it yet, it is thought that 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 Lychrel until proven otherwise. In addition you are given that for every number below ten-thousand, it will either (i) become a palindrome in less than fifty iterations, or, (ii) no one, with all the computing power that exists, has managed so far to map it to a palindrome. In fact, $10677$ is the first number to be shown to require over fifty iterations before producing a palindrome: $4668731596684224866951378664$ ($53$ iterations, $28$-digits).
Surprisingly, there are palindromic numbers that are themselves Lychrel numbers; the first example is $4994$.
How many Lychrel numbers are there below ten-thousand?
s
NOTE: Wording was modified slightly on 24 April 2007 to emphasise the theoretical nature of Lychrel numbers.
Problem 55: Lychrel Numbers
Mathematical Development
Formal Development
Definition 1 (Digit Reversal). For a positive integer with decimal representation (where ), define the digit reversal
Definition 2 (Reverse-and-Add Operator). The reverse-and-add operator is
For , denote the -fold composition with .
Definition 3 (Palindrome). An integer is a palindrome if , equivalently, if for all .
Definition 4 (Lychrel Candidate). For a positive integer bound , we say is a Lychrel candidate with respect to if is not a palindrome for all . In this problem, .
Theorem 1 (Digit Growth Bound). If has digits, then has at most digits.
Proof. Since has digits, . The reversal also has at most digits (it has exactly digits if , and fewer otherwise, but in all cases ). Therefore
so has at most digits.
Corollary 1 (Iterated Growth). Starting from with digits, the value has at most digits for all .
Proof. By induction on , applying Theorem 1 at each step.
Theorem 2 (Symmetrization Without Carries). Let . Then
In the absence of carries (i.e., when for all ), is a palindrome.
Proof. Without carries, the digit at position of is . Since , the digit at position equals the digit at position , so is a palindrome.
Corollary 2. Lychrel candidates arise only when carry propagation in repeatedly disrupts palindromic symmetry for at least consecutive iterations.
Theorem 3 (Carry Asymmetry Mechanism). When for some , a carry of 1 propagates to position . This carry may not have a symmetric counterpart at position , breaking the palindromic structure. Specifically, position receives a carry while position may not, creating asymmetric digits.
Proof. The carry from position adds 1 to the sum at position , making it . The symmetric position receives the sum (without carry, unless its own lower-order position generated a carry). Since carry propagation depends on the specific digits and proceeds left-to-right, the carry pattern at position need not match the carry pattern at position .
Remark. Whether any true Lychrel number exists in base 10 (i.e., one that never produces a palindrome regardless of the number of iterations) remains an open problem. The number 196 is the smallest candidate, with no palindrome found after more than iterations.
Editorial
We inspect every starting value below 10,000 independently. For each candidate, the reverse-and-add transformation is applied repeatedly for at most 50 steps, and after each step the new value is checked for palindromicity. If no palindrome appears within those 50 iterations, the starting value is counted as a Lychrel candidate under the problem’s convention.
Pseudocode
Algorithm: Counting Lychrel Numbers Below Ten Thousand
Require: The positive integers below 10^4.
Ensure: The number of starting values that do not produce a decimal palindrome within 50 reverse-and-add steps.
1: Initialize count ← 0.
2: For each starting value n in {1, 2, ..., 9999}, set x ← n and perform at most 50 reverse-and-add iterations.
3: After each iteration, if x has become a decimal palindrome, stop and classify n as non-Lychrel.
4: If the 50-step limit is reached without producing a palindrome, increment count.
5: Return count.
Complexity Analysis
Proposition 1 (Time). The algorithm tests integers, performing at most iterations each. By Corollary 1, after iterations starting from (at most 4 digits), has at most digits. Each iteration computes a reversal () and an addition () where . The palindrome check also costs . Total:
where is the maximum digit count. Since Python handles arbitrary-precision integers natively, no special big-number library is needed.
Proposition 2 (Space). for the current number during each iteration.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
// Arbitrary-precision addition using strings
string add(const string& a, const string& b) {
string result;
int carry = 0;
int i = a.size() - 1, j = b.size() - 1;
while (i >= 0 || j >= 0 || carry) {
int sum = carry;
if (i >= 0) sum += a[i--] - '0';
if (j >= 0) sum += b[j--] - '0';
result.push_back('0' + sum % 10);
carry = sum / 10;
}
reverse(result.begin(), result.end());
return result;
}
bool is_palindrome(const string& s) {
int n = s.size();
for (int i = 0; i < n / 2; i++)
if (s[i] != s[n - 1 - i]) return false;
return true;
}
bool is_lychrel(int n) {
string s = to_string(n);
for (int i = 0; i < 50; i++) {
string rev = s;
reverse(rev.begin(), rev.end());
s = add(s, rev);
if (is_palindrome(s)) return false;
}
return true;
}
int main() {
int count = 0;
for (int n = 1; n < 10000; n++) {
if (is_lychrel(n)) count++;
}
cout << count << endl;
return 0;
}
"""
Problem 55: Lychrel Numbers
How many Lychrel numbers are there below ten-thousand?
(Numbers that don't become palindromes within 50 iterations of reverse-and-add)
"""
def is_palindrome(n):
s = str(n)
return s == s[::-1]
def is_lychrel(n, max_iter=50):
for _ in range(max_iter):
n = n + int(str(n)[::-1])
if is_palindrome(n):
return False
return True
def solve():
count = sum(1 for n in range(1, 10000) if is_lychrel(n))
print(count)
solve()