#C11053. Happy Number Checker
Happy Number Checker
Happy Number Checker
Given a non-negative integer n, determine whether the number is a happy number or an unhappy number. A happy number is defined by the following process: starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1, or it enters a cycle that does not include 1.
Mathematically, if we define the transformation \( f(n) = \sum_{d \in D(n)} d^2 \), where \( D(n) \) is the set of digits of \( n \), then the number is happy if and only if iterating \( f \) eventually yields 1, i.e., \[ f(f(\dots f(n)\dots)) = 1. \]
If the process enters a cycle that never reaches 1, the number is considered unhappy. Note that 0 is considered an unhappy number.
inputFormat
The input consists of a single line containing one integer n (n ≥ 0).
outputFormat
Output a single line: Happy Number
if the number is happy, or Unhappy Number
otherwise.
19
Happy Number