#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; mt19937 mt{random_device{}()}; ll power(const ll p, const ll n, const ll mod) { if (n == 0) { return 1; } if (n % 2 == 1) { return (ll)((__int128_t)((__int128_t)power(p, n - 1, mod) * (__int128_t)p) % mod); } else { const __int128_t pp = power(p, n / 2, mod); return (ll)((__int128_t)(pp * pp) % mod); } } __int128_t power(const ll p, const ll n) { if (n == 0) { return 1; } if (n % 2 == 1) { return ((__int128_t)((__int128_t)power(p, n - 1) * (__int128_t)p)); } else { const __int128_t pp = power(p, n / 2); return ((__int128_t)(pp * pp)); } } bool isPrime(const ll n) { constexpr int TEST = 1000; ll s = 0; ll d = n - 1; while (d % 2 == 0) { s++; d /= 2; } uniform_int_distribution dist{1, n - 1}; for (int i = 0; i < TEST; i++) { const ll a = dist(mt); if (power(a, n - 1, n) != 1) { return false; } ll num = power(a, d, n); if (num != 1) { bool comp = true; for (ll r = 0; r < s; r++) { if (num == n - 1) { comp = false; break; } num = (ll)((__int128_t)((__int128_t)num * (__int128_t)num) % n); } if (comp) { return false; } } } return true; } ll root(const ll p, const int n, bool& rootable) { rootable = false; ll inf = 1; ll sup = 2 * (ll)pow(p, 1.0 / n); while (inf < sup) { const ll mid = (inf + sup) / 2; const __int128_t calc = power(mid, n); if (calc == p) { rootable = true; return mid; } else if (calc < p) { if (inf == mid) { break; } inf = mid; } else { sup = mid; } } return inf; } int main() { cin.tie(0); ios::sync_with_stdio(false); int Q; cin >> Q; for (int q = 0; q < Q; q++) { ll N; cin >> N; if (N == 1) { show(N); cout << "No" << endl; } else if (N == 2) { show(N); cout << "No" << endl; } else if (N % 2 == 0) { cout << "Yes" << endl; } else { bool ok = false; for (int i = 1; (1LL << i) < N; i++) { if (ok) { break; } const ll res = N - (1LL << i); for (int j = 1; j <= (int)log2(res * 2 - 1); j++) { if (ok) { break; } bool rootable = false; const ll rt = root(res, j, rootable); if (rootable) { if (isPrime(rt)) { ok = true; break; } } } } if (ok) { cout << "Yes" << endl; } else { show(N); cout << "No" << endl; } } } return 0; }