看了官方的题解后,自己瞎写的代码。题目样例中的几个测了下都过了,但是提交爆0。求指教哪里有问题,先谢谢了
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
long long x, z;
while (t--) {
cin >> x >> z;
long long d = sqrt(__gcd(x * x, z / x));
long long y = z / (x * d);
if (__gcd(x, y) != d) {
cout << -1 << endl;
} else {
cout << y << endl;
}
}
return 0;
}