#K6171. Lychrel Number Detection
Lychrel Number Detection
Lychrel Number Detection
You are given an integer \(n\) and a maximum number of iterations \(m\). Using the following iterative process:
\(n_{i+1} = n_i + \text{reverse}(n_i)\)
where \(\text{reverse}(n)\) denotes the integer obtained by reversing the digits of \(n\), your task is to determine the first palindrome number produced in the sequence. If a palindrome is found within \(m\) iterations, output that palindrome. Otherwise, output the string "LYCHREL". Note that if the process does not yield a palindrome within the given iterations, the number is considered a Lychrel number.
Special Cases: If the input is 0 or if the first iteration immediately results in a palindrome, handle accordingly.
inputFormat
The input consists of two lines read from standard input (stdin):
- The first line contains an integer \(n\), the starting number.
- The second line contains an integer \(m\), the maximum number of iterations allowed.
outputFormat
Output a single line to standard output (stdout) containing the palindrome number found by applying the iterative process. If no palindrome is found within \(m\) iterations, output LYCHREL
.
56
3
121