mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
[NOI Online 2022 普及组] 数学游戏(民间数据)
R72648237
This commit is contained in:
parent
ed7e55aea1
commit
e4a539a85b
36
Luogu/P8255/P8255.cpp
Normal file
36
Luogu/P8255/P8255.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user