#K83727. Happy Number Checker

    ID: 36262 Type: Default 1000ms 256MiB

Happy Number Checker

Happy Number Checker

Problem Description: A positive integer (n) is called a happy number if, starting with (n), the sequence defined by

[ n \to \sum_{d \in \text{digits}(n)} d^2 ]

eventually reaches 1. Otherwise, (n) is said to be an unhappy number. Your task is to determine whether each given number is happy or unhappy. Write a program that reads input from standard input (stdin) and outputs the result to standard output (stdout).

inputFormat

Input Format: The first line of the input contains an integer (T), representing the number of test cases. Each of the following (T) lines contains a single integer (n).

Constraints:

  • (1 \leq T \leq 10^4)
  • (1 \leq n \leq 10^9)

outputFormat

Output Format: For each test case, output "HAPPY" if the number is a happy number, or "UNHAPPY" otherwise, each on a separate line.## sample

4
19
20
7
4
HAPPY

UNHAPPY HAPPY UNHAPPY

</p>