mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-18 18:12:00 +00:00
37 lines
599 B
C++
37 lines
599 B
C++
|
#include <algorithm>
|
||
|
#include <cmath>
|
||
|
#include <iostream>
|
||
|
|
||
|
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;
|
||
|
}
|