#C10711. Happy Number Checker
Happy Number Checker
Happy Number Checker
A happy number is defined as follows: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers.
Your task is to determine if a given integer is a happy number. If the number eventually equals 1 after a series of transformations, output Happy
; otherwise, output Unhappy
.
The transformation can be mathematically described as follows: For a number \( n \), compute the next number as \( n' = \sum_{d \in D(n)} d^2 \), where \( D(n) \) is the set of digits of \( n \). Repeat the process until \( n=1 \) or a loop is detected.
inputFormat
The input consists of a single integer n
provided from standard input (stdin), where n
is the number you must evaluate.
outputFormat
Output a single line to standard output (stdout) containing either Happy
if the number is a happy number or Unhappy
otherwise.
19
Happy