Ankit_132

E2

Jul 7th, 2023 (edited)
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main()
  6. {
  7.     auto check = [](ll int x, ll int y)
  8.     {
  9.         ll int tot=0, p=1;
  10.  
  11.         for(ll int i=1; i<=y+1; i++)
  12.         {
  13.             tot += p;
  14.  
  15.             if(log10(p)+log10(x) > 18)      break;
  16.  
  17.             p *= x;
  18.         }
  19.  
  20.         return tot;
  21.     };
  22.  
  23.     int t;
  24.     cin>>t;
  25.     while(t--)
  26.     {
  27.         ll int n;
  28.         cin>>n;
  29.  
  30.         bool f = 0;
  31.  
  32.         for(int r=2; r<=60 && !f; r++)
  33.         {
  34.             ll int tmp = pow(n,((long double)1/r));
  35.  
  36.             if(tmp>=2 && check(tmp, r)==n)
  37.                 f=1;
  38.         }
  39.  
  40.         if(f)           cout<<"YES\n";
  41.         else            cout<<"NO\n";
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment