/****************************************** * AUTHOR: BHUVNESH JAIN * * INSTITUITION: BITS PILANI, PILANI * ******************************************/ #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; #define inchar getchar_unlocked #define outchar(x) putchar_unlocked(x) template<typename T> void inpos(T &x) { x = 0;register T c = inchar(); while(((c<48) || (c>57)) && (c!='-')) c = inchar(); bool neg = false; if (c=='-') neg=true; for(; c<48 || c>57; c = inchar()) ; for(; c>47 && c<58; c = inchar()) x = (x<<3)+(x<<1)+(c&15); if(neg) x = -x; } template<typename T> void outpos(T n) { if(n<0) outchar('-'), n *= -1; char snum[65]; int i=0; do { snum[i++] = n % 10 + '0'; n /= 10; } while(n); i = i - 1; while (i>=0) outchar(snum[i--]); outchar('\n'); } template<typename T> T gcd(T a, T b) { return (b ? __gcd(a,b): a); } int mul(int a, int b, int c) { LL res = (LL)a * b; return (res >= c ? res % c : res); } template <typename T>T power(T e, T n, T m) { T x = 1, p = e; while(n) { if(n & 1) x = mul(x, p, m); p = mul(p, p, m); n >>= 1; } return x; } const int MAX = 101; int lp[MAX]; vector<int> primes; void factor_sieve() { lp[1] = 1; for (int i=2; i<MAX; ++i) { if (lp[i] == 0) { lp[i] = i; primes.emplace_back(i); } for (int j=0; j<primes.size() && primes[j]<=lp[i]; ++j) { int x = i * primes[j]; if (x >= MAX) break; lp[x] = primes[j]; } } } int main() { #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif factor_sieve(); int t, n, k; inpos(t); while(t--) { inpos(n), inpos(k); int vol = n * n * n; int left = vol - k; if (left == 0 || left == vol) { puts("YES"); continue; } bool solve = true; /* cube root in finite field "n" exits when cube root for every pi^ki exist where n = p1^k1 * p2^k2 * ... pl^kl Here n = volume */ while(n != 1 && solve) { int p = lp[n], pk = 1; while(n % p == 0) { n /= p; //power of pk in vol will be p^3 pk *= p * p * p; } //equation x^3 = left (mod pk) int a = left % pk; //a = 0 means, x = 0 exists if (!a) continue; int chk = 0; /* find power of "p" in a if it is not multiple of 3, we can get triplets in x, hence answer doesn't exist */ while(a % p == 0) { a /= p; chk += 1; } if (chk % 3) {solve = 0; continue;} //now condition gcd(a, pk) = 1 holds as per Hensel's lemma if (p == 2) { /* check if a^(phi[pk]/d) = 1 mod(pk) where d = gcd(phi[pk], t) here t = 3, "d" will always be 1. Thus, by Euler theorem a^phi(x) = 1 (mod x) for every x. Thus, no need to check here. */ } else { /* check if a^(phi[pk]/d) = 1 mod(pk) where d = gcd(phi[pk], t) here t = 3, fixed */ int phi = pk / p * (p - 1); if(power(a, phi/gcd(phi, 3), pk) > 1) { solve = false; } } } if (solve) { puts("YES"); } else { puts("NO"); } } // cout<<"Execution time : "<<tick()<<"\n"; return 0; }