BlackrockOA #5
Happy Number
EasyJudge-ready
Topics (AI-labelled)HashingBits & Math
Given a positive integer n, repeatedly replace it with the sum of the squares of its digits. If the process reaches 1, output the happy-number marker; if it enters a cycle that does not contain 1, output the non-happy-number marker.
Input
A single integer n, 1≤n≤2147483647.
Output
Output 1 for a happy number, otherwise output 0.
Example 1
Input:
19
Output:
1
Example 2
Input:
2
Output:
0
Example 3
Input:
11
Output:
0
Editorial
Loading solution…