mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 23:48:48 +00:00
37 lines
599 B
C++
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;
|
|
}
|