Happy Number

EasyMath
Next
MathHash SetCycle Detection

Start with a positive integer and repeatedly replace it with the sum of the squares of its digits. The number is happy if this process eventually reaches 1, and unhappy if it loops forever in a cycle that does not include 1. Decide whether the number is happy.

Input

A single integer n.

Output

Print true if n is happy, otherwise false.

Constraints

1 <= n <= 2^31 - 1

Example 1
Input
19
Output
true

19 -> 82 -> 68 -> 100 -> 1, so it is happy.

Example 2
Input
2
Output
false

2 -> 4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4, a cycle.

Hints

Happy Number - Easy Math Problem | Skill Shiksha