Advertisement
yuawn

algo2017_week2_happynumber

Oct 3rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int fuck( int n ){
  5.     int sum = 0;
  6.     while( n ){
  7.         int c = n % 10;
  8.         sum += c * c;
  9.         n /= 10;
  10.     }
  11.     return sum;
  12. }
  13.  
  14. int main(){
  15.     int t , n;
  16.     cin >> t;
  17.     while( t-- ){
  18.         cin >> n;
  19.         while( n > 9 ) n = fuck( n );
  20.         if( n == 1 ) puts("Happy");
  21.         else puts("Not Happy");
  22.     }
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement