-
Notifications
You must be signed in to change notification settings - Fork 0
/
10591.cpp
54 lines (48 loc) · 940 Bytes
/
10591.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
10591 - Happy Number
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int test;
cin>>test;
for(int loop=1; loop<=test; loop++)
{
ll i,j,k,n,sum,num,d;
cin>>n;
num =n;
for(j=1; j!=0; j++)
{
sum =0;
for(i=1; i!=0; i++)
{
d = num%10;
num=num/10;
sum = sum + d*d;
if(num==0)
{
num = sum;
break;
}
}
if(num<=9)break;
}
if(num==1 || num==7) printf("Case #%d: %lld is a Happy number.\n",loop,n);
else
printf("Case #%d: %lld is an Unhappy number.\n",loop,n);
}
return 0;
}
/*
Sample Input
3
7
4
13
Sample Output
Case #1: 7 is a Happy number.
Case #2: 4 is an Unhappy number.
Case #3: 13 is a Happy number.
*/