#K6401. Happy Number Checker

    ID: 31880 Type: Default 1000ms 256MiB

Happy Number Checker

Happy Number Checker

In this problem, you are given a positive integer and you need to determine whether it is a "Happy Number" or not. A number ( n ) is said to be happy if the following process eventually leads to the value 1: replace the number by the sum of the squares of its digits. Formally, define ( f(n) = \sum (\text{digit})^2 ). Repeat this process until ( n=1 ) or the process loops endlessly in a cycle which does not include 1. Your task is to implement this logic for several test cases.

For example, for ( n=19 ), the process is: (19 \to 1^2+9^2=82\to 8^2+2^2=68\to 6^2+8^2=100\to 1^2+0^2+0^2=1). Since the process ends in 1, 19 is a happy number.

inputFormat

The input begins with an integer ( T ), the number of test cases. Each of the following ( T ) lines contains a single positive integer ( n ) representing a test case.

outputFormat

For each test case, output a single line containing the string "HAPPY" if ( n ) is a Happy Number, otherwise output "UNHAPPY".## sample

1
19
HAPPY

</p>