Advertisement
fahimkamal63

Narcissistic number

Jun 23rd, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. bool arm(int n){
  6.     int temp = n, power = 0;
  7.     while(temp){
  8.         power++;
  9.         temp /= 10;
  10.     }
  11.     temp = n; int ans = 0;
  12.     while(temp){
  13.         ans += (pow((temp % 10), power));
  14.         temp /= 10;
  15.     }
  16.     if(ans == n) return true;
  17.     return false;
  18. }
  19.  
  20. int main(){
  21.     int t; cin >> t;
  22.     while(t--){
  23.         int n; cin >> n;
  24.         if(arm(n)) cout << "Yes\n";
  25.         else cout << "No\n";
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement