#C4981. Happy Number Checker
Happy Number Checker
Happy Number Checker
This problem asks you to determine whether a given integer is a Happy Number. A number is considered happy if, after a sequence of steps computing the sum of the squares of its digits, the result becomes 1. Otherwise, the process falls into an endless loop.
Formally, define the function:
[ S(n) = \sum_{d \in \text{digits of } n} d^2 ]
Starting from the initial number \(n\), repeatedly replace \(n\) with \(S(n)\). If the process terminates in 1, then the number is happy, otherwise it is not.
For example, for \(n = 19\):
19 \(\to\) 1^2 + 9^2 = 1 + 81 = 82 82 \(\to\) 8^2 + 2^2 = 64 + 4 = 68 68 \(\to\) 6^2 + 8^2 = 36 + 64 = 100 100 \(\to\) 1^2 + 0^2 + 0^2 = 1 + 0 + 0 = 1
Thus, 19 is a Happy Number.
inputFormat
The input consists of a single integer n provided via STDIN.
outputFormat
Output a single line to STDOUT containing True
if n is a Happy Number, otherwise output False
.
19
True