0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 05:38:47 +00:00
OI-codes/Luogu/P8255/P8255.cpp

37 lines
599 B
C++
Raw Normal View History

2022-06-01 01:45:41 +00:00
#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;
}