Statementâ–¼
Write an algorithm to determine if a number n is a happy number.
We use the following process to check if a given number is a happy number:
- Starting with the given number n, replace the number with the sum of the squares of its digits.
- Repeat the process until:
- The number equals 1, which will depict that the given number n is a happy number.
- It enters a cycle, which will depict that the given number n is not a happy number.
Return TRUE if n is a happy number, and FALSE if not.
Constraints
- 1≤ n ≤231−1