0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-26 05:32:03 +00:00
OI-codes/Luogu/P8255/P8255.cpp

37 lines
599 B
C++

#include <iostream>
#include <algorithm>
#include <cmath>
using std::cin;
using std::cout;
const char endl = '\n';
int t;
long long x, z;
int main() {
std::ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> x >> z;
if (!z) {
cout << 0 << endl;
continue;
}
long long yg = z / x,
gg = std::__gcd(x * x, yg),
g = std::sqrt(gg);
if (gg != g * g || z % x) {
cout << -1 << endl;
} else {
cout << yg / g << endl;
}
}
return 0;
}