#include<bits/stdc++.h>
#define l unsigned long long int
using namespace std;
l i, m;
void happy(l n)
{
l r, d = 0;
while(n != 0)
{
r = n%10;
n = n/10;
d += (r*r);
}
n = d;
if(n<=9)
{
if(n == 1 || n == 7)
cout << "Case #" << i << ": "<< m << " is a Happy number." << endl;
else
cout << "Case #" << i << ": "<< m << " is an Unhappy number." << endl;
return;
}
happy(n);
}
int main()
{
l n;
cin >>n;
for(i=1; i<=n; i++)
{
cin >> m;
happy(m);
}
return 0;
}
#define l unsigned long long int
using namespace std;
l i, m;
void happy(l n)
{
l r, d = 0;
while(n != 0)
{
r = n%10;
n = n/10;
d += (r*r);
}
n = d;
if(n<=9)
{
if(n == 1 || n == 7)
cout << "Case #" << i << ": "<< m << " is a Happy number." << endl;
else
cout << "Case #" << i << ": "<< m << " is an Unhappy number." << endl;
return;
}
happy(n);
}
int main()
{
l n;
cin >>n;
for(i=1; i<=n; i++)
{
cin >> m;
happy(m);
}
return 0;
}
Comments
Post a Comment