HPYNOS  Happy Numbers I
The process of “breaking” an integer is defined as summing the squares of its digits. For example, the result of breaking the integer 125 is (1^{2} + 2^{2} + 5^{2}) = 30. An integer N is happy if after “breaking” it repeatedly the result reaches 1. If the result never reaches 1 no matter how many times the “breaking” is repeated, then N is not a happy number.
TASK
Write a program that given an integer N, determines whether it is a happy number or not.
CONSTRAINTS
2 ≤ N ≤ 2,147,483,647
Input
A single line containing a single integer N.
Output
A single line containing a single integer T which is the number of times the process had to be done to determine that N is happy, or 1 if N is not happy.
Example
Input: 19 Output: 4
1) 19 : 1^{2} + 9^{2} = 82 2) 82 : 82 + 2^{2} = 68 3) 68 : 6^{2} + 8^{2} = 100 4) 100 : 1^{2 }+ 0^{2} + 0^{2} = 1
The solution is 4 because we discovered that the integer 19 is happy after we repeated the process 4 times.
Input: 204 Output: 1
204 –> 20 –> 4 –> 16 –> 37 –> 58 –> 89 –> 145 –> 42 –> 20 –> 4 –> 16 –> 37 –> 58 –> 89 –> 145 ……
204 is not a happy number because after breaking it several times the results start repeating so we can deduce that if we continue breaking it, the result will never reach 1.
Number of input files is 32.
Don't use precalculated values (Don't Cheat)!!!
hide comments
ankur314:
20180621 10:23:26
when i took number of i/p files=32 i got WA


akshay_22:
20180527 06:56:16
My time to really show off!!! xD


syamphanindra:
20180507 13:48:16
good problem .Tracing 32 nd case is tough for someone.If you give up search for 32nd test case in my blog. Last edit: 20180507 13:48:30 

abhinav__:
20180402 18:20:20
Bill got AC in 1 go.


divya063:
20180320 13:51:21
AC in one go without using cycle detection! 

ayusofayush:
20180223 15:41:12
AC in one go!!!


srjsunny:
20180206 17:19:55
@jayeshd thanks alot found another way without using Floyd's cycle. 

vikramvarun:
20180112 00:24:08
Getting WA after more than 20 test cases. Could someone suggest some conditions that I might be missing? Solution id is 20968234. 

amankumarjha:
20180101 17:52:12
Learnt to use set, what set insert returns and how to receive and compare whether value was inserted in addition to operating with digits 

johansherlock:
20171130 12:36:09
AC in first time...

Added by:  Rofael Emil 
Date:  20101103 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Egyptian Olympiad in Informatics ( EOI ) 2009, August 14  21, Cairo 