#C2122. Happy Number Classifier
Happy Number Classifier
Happy Number Classifier
A Happy Number is defined by the following process: Start with any non-negative integer \( n \). Replace the number by the sum of the squares of its digits, i.e., compute \( \sum_{i=1}^{k} d_i^2 \) where \( d_i \) are the digits of \( n \). Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. If the process ends in 1, then \( n \) is a Happy Number; otherwise, it is an Unhappy Number.
Your task is to write a program that, given a series of numbers, classifies each number as either "HAPPY" if it is a Happy Number, or "UNHAPPY" otherwise.
Note: A number less than or equal to 0 should be considered UNHAPPY.
inputFormat
The first line of the input contains a single integer \( T \) representing the number of test cases. This is followed by a single line containing \( T \) space-separated integers. Each integer represents a test case.
Example:
3 19 2 7
outputFormat
For each test case, output a single line containing either "HAPPY" if the given number is a Happy Number, or "UNHAPPY" otherwise.
Example:
HAPPY UNHAPPY HAPPY## sample
3
19 2 7
HAPPY
UNHAPPY
HAPPY
</p>