← 返回 snowflake 的题目列表Happy Number
类型:online_judge
Problem: Happy Number
Given a positive integer n, determine whether it is a happy number.
A happy number is defined as follows:
Start with any positive integer.
Replace the number by the sum of the squares of its digits.
Repeat the process.
If the number eventually becomes 1, it is a happy number.
If the process falls into a cycle that does not include 1, it is not a happy number.
Implement a program that reads an integer n and prints whether it is a happy number.
Input Format
n
Output Format
Print:
true
if n is a happy number, otherwise print:
false
Constraints
1 <= n <= 2^31 - 1
Example 1
Input:
19
Output:
true
Explanation:
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1
Example 2
Input:
2
Output:
false
Example
Input
19
Output
true