Given a no N your task is to find whether its a happy no or not . A number is called happy if it leads to 1 after a sequence of steps where in each step number is replaced by sum of squares of its digit that is if we start with Happy Number and keep replacing it with digits square sum, we reach 1.
Input: n = 19 Output: 1 19 is Happy Number, 1^2 + 9^2 = 82 8^2 + 2^2 = 68 6^2 + 8^2 = 100 1^2 + 0^2 + 0^2 = 1 As we reached to 1, 19 is a Happy Number. Input: n = 20 Output: 0
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow . The first line of each test case contains an integer N.
For each test case in a new line print 1 if the no is a happy else print 0.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.