Advertisement
pb_jiang

1846E2 AC

Jul 8th, 2023
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #ifndef __DEBUG__
  5. #define dbg(...) 42
  6. #endif
  7. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  8.  
  9. using ll = long long;
  10. using pii = pair<int, int>;
  11. using pll = pair<ll, ll>;
  12. using vl = vector<ll>;
  13. using vi = vector<int>;
  14. using ull = unsigned long long;
  15. using ld = long double;
  16.  
  17. // constexpr ll p1 = (1ll << 50) - 51, p2 = (1ll << 50) - 117;
  18. constexpr ll p1 = (1ll << 30) - 35, p2 = (1ll << 30) - 41;
  19.  
  20. ll fpow(ll b, ll p, ll m)
  21. {
  22.     ll ret = 1;
  23.     ll cur = b;
  24.     while (p) {
  25.         if (p % 2)
  26.             ret = ret * cur % m;
  27.         cur = cur * cur % m;
  28.         p /= 2;
  29.     }
  30.     return ret;
  31. }
  32.  
  33. int main(int argc, char **argv)
  34. {
  35.     ll t, n;
  36.     cin >> t;
  37.     while (t--) {
  38.         cin >> n;
  39.         bool ok = false;
  40.         for (ll p = 3; p <= 90 && !ok; ++p) {
  41.             ll lb = powl(n, 1.0 / (p - 1));
  42.             auto fmod = [p](ll k) {
  43.                 return pll{(fpow(k, p, p1) + p1 - 1) % p1 * fpow(k - 1, p1 - 2, p1) % p1,
  44.                            (fpow(k, p, p2) + p2 - 1) % p2 * fpow(k - 1, p2 - 2, p2) % p2};
  45.             };
  46.             if (fmod(lb) == pll{n % p1, n % p2})
  47.                 ok = true;
  48.             else
  49.                 dbg(lb, p, n, fmod(lb), n % p1, n % p2);
  50.         }
  51.         cout << (ok ? "YES" : "NO") << endl;
  52.     }
  53.     return 0;
  54. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement