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
ankit1cool:
20160819 21:58:50
no memoization just write main function for 1 file


manish3749:
20160813 23:39:41
trick is hidden in the e.g . 204 

deepika10:
20160726 13:28:11
AC in one go. Absolutely simple logic. NO memoization needed. The solution is as simple as it looks like. 

mattmurdock:
20160717 16:27:10
Memoization.


Guru Bala Dhinesh:
20160707 15:44:09
Nobody asked for number of input files. cost me 1 NZEC. 

wesolyfoton:
20160627 03:04:24
Since when precalculating is a cheating?!? 

roy_24:
20160624 16:44:33
Dont complicate, can be done without using stl or memoization. Think easy. 

baadshah_:
20160623 13:50:44
use set STL


noob909:
20160616 07:08:29
memoization :D ac in 1 go! 

vineetpratik:
20160613 19:13:09
Ac in one go , :D m happy. 
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 