Lychrel Number is a natural number that cannot form a palindrome through the iterative process of repeatedly reversing its digits and adding the resulting numbers. The process is sometimes called the 196-algorithm, after the most famous number associated with the process.
The first few numbers not known to produce palindromes when applying the 196-algorithm (i.e., a reverse-then-add sequence) are sometimes known as Lychrel numbers.
Input : 56 Output : 56 is lychrel : false Explanation : 56 becomes palindromic after one iteration : 56 + 65 = 121 Input : 196 Output : 196 is lychrel : true Explanation : 196 becomes palindromic after 19 iterations : 196 + 691 = 887 887 + 788 = 1675 1675 + 5761 = 7436 7436 + 6347 = 13783 13783 + 38731 = 52514 .... 16403234045 + 54043230461 70446464506 + 60546464407
The task is to find if a given number is Lycheral with given limit on number of iterations.
1. Iterate given number of times 1. Add number to it's reverse 2. If the newly formed number is palindrome then return false // Number is not lychrel. 2. return true // Number is lychrel
295 is lychrel ? true
This article is contributed by Pramod Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Fizz Buzz Implementation
- Implementation of Wilson Primality test
- Cubic Bezier Curve Implementation in C
- Dixon's Factorization Method with implementation
- Window to Viewport Transformation in Computer Graphics with Implementation
- Implementation of Non-Restoring Division Algorithm for Unsigned Integer
- Implementation of Restoring Division Algorithm for unsigned integer
- Chinese Remainder Theorem | Set 2 (Inverse Modulo based Implementation)
- Number of factors of very large number N modulo M where M is any prime number
- Find minimum number to be divided to make a number a perfect square
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count number of triplets with product equal to given number with duplicates allowed
- Find the largest number smaller than integer N with maximum number of set bits
- Minimum divisor of a number to make the number perfect cube
- Find the minimum number to be added to N to make it a prime number
- Find smallest possible Number from a given large Number with same count of digits
- Number of distinct ways to represent a number as sum of K unique primes
- Smallest number dividing minimum number of elements in the Array
- Smallest number dividing minimum number of elements in the array | Set 2
- Number of times the largest perfect square number can be subtracted from N