def getAllFactors(x): factors=[]
for i in range(1,int(x**0.5)+1):
if x%i==0:
factors.append(i)
if x//i!=i:
factors.append(x//i)
return sorted(factors)
def main():
t = int(input())
allans = []
for _ in range(t):
x, d = readIntArr()
nSplit = 0
while x % d == 0:
x //= d
nSplit += 1
if nSplit == 1:
ans = 'no'
else:
ans = 'no'
xdivisors = getAllFactors(x)
ddivisors = getAllFactors(d)
if 1 in xdivisors: xdivisors.remove(1);
if x in xdivisors: xdivisors.remove(x)
if 1 in ddivisors: ddivisors.remove(1);
if d in ddivisors: ddivisors.remove(d)
if len(xdivisors) > 0: ans = 'yes'
elif nSplit == 3:
for ddiv in ddivisors:
if (ddiv * x) % d != 0:
ans = 'yes'
elif nSplit > 3:
if len(ddivisors) > 0:
ans = 'yes'
allans.append(ans)
multiLineArrayPrint(allans)
return
import sys
input=sys.stdin.buffer.readline
def oneLineArrayPrint(arr):
print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultValFactory,dimensionArr): dv=defaultValFactory;da=dimensionArr
if len(da)==1:return [dv() for _ in range(da[0])]
else:return [makeArr(dv,da[1:]) for _ in range(da[0])]
def queryInteractive(a, b, c):
print('? {} {} {}'.format(a, b, c))
sys.stdout.flush()
return int(input())
def answerInteractive(x1, x2):
print('! {} {}'.format(x1, x2))
sys.stdout.flush()
inf=float('inf')
from math import gcd,floor,ceil
import math
for _abc in range(1):
main()
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include <numeric>
#include <time.h>
#include <numeric>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <random>
#include <algorithm>
#include <optional>
#include <set>
using namespace std;
//typedef long long int ll;
#define cin1(a) cin >> a;
#define cin2(a, b) cin >> a >> b;
#define cin3(a, b, c) cin >> a >> b >> c;
#define cinvec(vec) for(auto& it: vec) {cin1(it);}
#define coutvec(vec) for(auto it: vec) {cout << it << " ";} cout << endl;
//#define endl '\n';
using namespace std;
#define int int64_t
bool isPrime(int x) {
if (x <= 1) return true;
for (int i = 2; (i * i) <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int primesCnt(int x) {
int res = 0;
if (x <= 1) return res;
int x_b = x;
for (int i = 2; (i * i) <= x_b; i++) {
while (x % i == 0) {
x /= i;
res++;
}
}
if (x != 1) res++;
return res;
}
set<int> difPrimes(int x) {
set<int> res;
if (x <= 1) return res;
int x_b = x;
for (int i = 2; (i * i) <= x_b; i++) {
while (x % i == 0) {
x /= i;
res.insert(i);
}
}
if (x != 1) res.insert(x);
return res;
}
string solve() {
int x, d;
cin2(x, d);
int degsCnt = 0;
while (x % d == 0) {
x /= d;
degsCnt++;
}
if (degsCnt == 1) return "No";
if (!isPrime(x)) return "Yes";
if (isPrime(d)) return "No";
if (degsCnt == 2) return "No";
int dPrimesCnt = primesCnt(d);
if (x == 1) {
return "Yes";
}
else {
set<int> dif = difPrimes(d);
if (degsCnt == 3) {
if (dif.size() == 1) {
if ((dPrimesCnt <= 2) && dif.count(x)) return "No";
else return "Yes";
}
else {
return "Yes";
}
}
else { // degsCnt > 3
return "Yes";
}
}
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin1(t);
//t = 1;
while (t--) {
//solve();
cout << solve() << endl;
}
return 0;
}
1671B - Consecutive Points Segment | 1671C - Dolce Vita |
1669G - Fall Down | 4D - Mysterious Present |
1316B - String Modification | 1204A - BowWow and the Timetable |
508B - Anton and currency you all know | 1672A - Log Chopping |
300A - Array | 48D - Permutations |
677C - Vanya and Label | 1583B - Omkar and Heavenly Tree |
1703C - Cypher | 1511C - Yet Another Card Deck |
1698A - XOR Mixup | 1702E - Split Into Two Sets |
1703B - ICPC Balloons | 1702F - Equate Multisets |
1700A - Optimal Path | 665C - Simple Strings |
1708A - Difference Operations | 1703E - Mirror Grid |
1042A - Benches | 1676B - Equal Candies |
1705B - Mark the Dust Sweeper | 1711A - Perfect Permutation |
1701B - Permutation | 1692A - Marathon |
1066A - Vova and Train | 169B - Replacing Digits |