111. Happy Number

Acceptance — 0 accepted 0 submissions

Easy
HashingMath
No companies listed
Take a number, replace it with the sum of the squares of its digits, and repeat. If you eventually reach 1, the number is happy. If you get stuck in a loop that never reaches 1, it's not.

Example: 19 → 1² + 9² = 82 → 68 → 100 → 1. So 19 is happy.

Input Format
A single integer n.

Output Format
Print Happy or Not Happy.

Constraints
• 1 ≤ n ≤ 10^9

Example 1

Input
19
Output
Happy

Explanation 19 → 82 → 68 → 100 → 1.

Example 2

Input
2
Output
Not Happy

Explanation 2 → 4 → 16 → 37 → … loops forever without reaching 1.

Example 3

Input
1
Output
Happy

Explanation Already 1.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
Happy
No results yet
Run your code to test it against the sample cases.
Problem List