#K44032. Happy Number Chains
Happy Number Chains
Happy Number Chains
Given a list of positive integers, determine for each whether it is a happy number. A number \(n\) is called happy if the following process eventually reaches 1:
Replace \(n\) by the sum of the squares of its digits, i.e. compute $$S(n)=\sum_{i=1}^{k} d_i^2$$ where \(d_i\) are the digits of \(n\). Repeat the process until \(n=1\) (in which case \(n\) is happy) or it loops endlessly in a cycle that does not include 1 (not a happy number).
Your task is to determine for each given number whether it is happy.
inputFormat
The input is given via standard input. The first line contains a single integer (T), the number of test cases. Each of the following (T) lines contains one positive integer (n).
outputFormat
For each test case, output a single line containing "YES" if (n) is a happy number, otherwise output "NO".## sample
3
19 2 7
YES
NO
YES
</p>