Saleh127

UVA 10591

Sep 12th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5.  
  6. ll xxx(ll x)
  7. {
  8. ll r=0,i;
  9. while(x)
  10. {
  11. i=x%10;
  12. r+=(i*i);
  13. x/=10;
  14. }
  15. return r;
  16. }
  17.  
  18. int main()
  19. {
  20. ios_base::sync_with_stdio(0);
  21. cin.tie(0);cout.tie(0);
  22.  
  23. test
  24. {
  25. ll a,c,d,e,f,i,j=0,k=0,l;
  26. cin>>a;
  27. c=a;
  28. while(k<=1000)
  29. {
  30. a=xxx(a);
  31. if(a==1)
  32. {
  33. j=1;
  34. break;
  35. }
  36. if(a==c)
  37. {
  38. j=0;
  39. break;
  40. }
  41. k++;
  42. }
  43. if(j==1) cout<<"Case #"<<cs<<": "<<c<<" is a Happy number."<<endl;
  44. else cout<<"Case #"<<cs<<": "<<c<<" is an Unhappy number."<<endl;
  45.  
  46. }
  47. return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment