Ankit_132

E1

Jul 7th, 2023
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define ff     first
  9. #define ss     second
  10. #define pb     push_back
  11. #define ppb    pop_back
  12.  
  13. int main()
  14. {
  15.     ios_base::sync_with_stdio(false);
  16.     cin.tie(NULL);
  17.     cout.tie(NULL);
  18.  
  19.     int N = 1e6 + 5;
  20.  
  21.     vector<int> pos(N);
  22.  
  23.     for(ll int k=2;;k++)
  24.     {
  25.         ll int tot = 1 + k + k*1ll*k;
  26.         ll int x = k*k;
  27.  
  28.         if(tot > N)     break;
  29.  
  30.         while(tot < N && tot>0)
  31.         {
  32.             pos[tot] = 1;
  33.             tot += x*k;
  34.             x *= k;
  35.         }
  36.     }
  37.  
  38.     _test
  39.     {
  40.         int n;
  41.         cin>>n;
  42.  
  43.         if(pos[n])      cout<<"YES\n";
  44.         else            cout<<"NO\n";
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment