#include <cstdio>
#include <iostream>
#include <cstring>
#include <list>
#include <algorithm>
using namespace std;
int vis[1000];
int solve(int n)
{
int sum = 0;
while(n>0)
{
sum += (n%10)*(n%10);
n /= 10;
}
return sum;
}
int main()
{
int n, x, casen = 1;
cin >> n;
while(n--)
{
cin >> x;
memset(vis, 0, sizeof(vis));
int m = x;
while(x)
{
m = solve(m);
if(m == 1)
{
printf("Case #%d: %d is a Happy number.\n", casen++, x);
break;
}
if(vis[m])
{
printf("Case #%d: %d is an Unhappy number.\n", casen++, x);
break;
}
vis[m] = 1;
}
}
return 0;
}
uva 10591- Happy Number
最新推荐文章于 2019-04-29 13:34:38 发布