我不理解,经对拍,样例3可以过,但luogu提交爆0qwq
#include<bits/stdc++.h>
#define ll long long
#define gcd gcd123
using namespace std;
ll t, x, z, ma, ans, te;
ll gcd(ll a, ll b){
if(a % b == 0)
return b;
return gcd(b % a, a);
}
bool check(ll i){
return (te % i == 0 && (te / i) % i == 0 && gcd(x, te / i) == i);
}
int main(){
// freopen("math.in", "r", stdin);
// freopen("math.out", "w", stdout);
scanf("%lld", &t);
while(t --){
scanf("%lld%lld", &x, &z);
if(z % x != 0){
printf("-1\n");
break;
}
ma = sqrt(x), te = z / x, ans = -1;
for(ll i = 1; i <= ma; i ++){
if(x % i == 0){
if(check(i)){
if(ans == -1 || te / i < ans)
ans = te / i;
}
if(check(x / i)){
if(ans == -1 || te / (x / i) < ans)
ans = te / (x / i);
}
}
}
if(ans == INT_MAX)
printf("-1\n");
else
printf("%lld\n", ans);
}
return 0;
}