eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Unhappy Numbers

Unhappy Numbers

Numbers have feelings too! For any positive integer, take the sum of the squares of each of its digits, and add them together. Take the result, and do it again. A number is \textit{happy} if, after repeating this process a finite number of times, the sum is \textbf{1}. Some happy numbers take more iterations of this process to get to \textbf{1} than others, and that would be referred to as its distance from happiness. \textbf{1}'s distance from happiness is \textbf{0}. \textbf{23}'s distance from happiness is \textbf{3}, since \textbf{2^2+ 3^2 = 13}, \textbf{1^2 + 3^2 = 10}, and \textbf{1^2 + 0^2 = 1}. Numbers are \textit{unhappy} if they are infinitely far away from happiness because they get stuck in a loop. Given the lower end and upper end of a range of integers, determine how many Unhappy numbers are in that range (inclusive). \InputFile There will be several test cases in the input. Each test case will consist of two positive integers, \textbf{lo} and \textbf{hi} (\textbf{0} < \textbf{lo} ≤ \textbf{hi }≤ \textbf{10^18}) on a single line, with a single space between them. Input will terminate with two \textbf{0}s. \OutputFile For each test case, output a single integer on its own line, indicating the count of \textit{unhappy numbers} between \textbf{lo} and \textbf{hi }(inclusive). Output no extra spaces, and do not separate answers with blank lines.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
1 10
1 100
0 0
Вихідні дані #1
7
80