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
sinersnvrsleep:
20171112 05:41:00
ac in second go minor mistake Last edit: 20171112 11:33:21 

kush_pathak01:
20171016 10:30:06
AC in one go!!solved in less than 10 minutes...no thinking required 

deepak097:
20170917 14:14:42
Take 3 hr but finally AC !! huh.. 

jayeshd:
20170908 20:42:23
The theoretical maxima of a loop length will be very less and can be a good problem in itself (given N ≤ 2,147,483,647). The max sum of squares can be 1^2 + 81*9 = 730, in the next step the number would become even lesser. So we can be pretty sure that even if there is a loop its length will be in 3 digits. Though actually, the highest loop size is just 20 given N ≤ 2,147,483,647. Last edit: 20170908 20:42:55 

addy1397:
20170724 10:56:17
7 sucks ...right! 

ramesh_961:
20170604 14:04:09
can Learn Floyd's cycle detection!! Easy!! 

akababa:
20170426 07:25:00
How would you even use precalculated valuess... lol 

visu27:
20170323 10:21:21
easy one AC in one go 

stark_attack:
20170223 11:34:14
very easy , with just two loops .AC in first go ..... 

cake_is_a_lie:
20170211 00:37:59
Lots of ways to solve this, but for me the thought pattern was "if only I could easily find a bound on the number of iterations it might take to reach 1"... 
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 