#include <iostream>
#include<cstring>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int re(long long num)
{
char ss[100];
long long sum=0;
sprintf(ss,"%lld",num);
int len=strlen(ss);
for(int i=0;i<len;i++)
{
int x=ss[i]-'0';
sum+=x*x;
}
// cout<<sum<<endl;
char chr[200];
sprintf(chr,"%lld",sum);
int l=strlen(chr);
if(l==1)
{
return sum;
}
else return re(sum);
}
int main()
{
int test,cnt=0;
scanf("%d",&test);
while(test--)
{
long long num;
scanf("%lld",&num);
int H=re(num);
if(H==1)
{
printf("Case #%d: %lld is a Happy number.\n",++cnt,num);
}
else
{
printf("Case #%d: %lld is an Unhappy number.\n",++cnt,num);
}
}
return 0;
}
#include<cstring>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int re(long long num)
{
char ss[100];
long long sum=0;
sprintf(ss,"%lld",num);
int len=strlen(ss);
for(int i=0;i<len;i++)
{
int x=ss[i]-'0';
sum+=x*x;
}
// cout<<sum<<endl;
char chr[200];
sprintf(chr,"%lld",sum);
int l=strlen(chr);
if(l==1)
{
return sum;
}
else return re(sum);
}
int main()
{
int test,cnt=0;
scanf("%d",&test);
while(test--)
{
long long num;
scanf("%lld",&num);
int H=re(num);
if(H==1)
{
printf("Case #%d: %lld is a Happy number.\n",++cnt,num);
}
else
{
printf("Case #%d: %lld is an Unhappy number.\n",++cnt,num);
}
}
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন