mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 19:08:47 +00:00
#1929. 【Gym103446D】Strange Fractions
https://sjzezoj.com/submission/70572
This commit is contained in:
parent
cdc7396d81
commit
394dec7271
46
S2OJ/1929/1929.cpp
Normal file
46
S2OJ/1929/1929.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <experimental/numeric>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
void solve() {
|
||||
long long p, q;
|
||||
|
||||
cin >> p >> q;
|
||||
|
||||
long long g = std::experimental::gcd(p, q);
|
||||
|
||||
p /= g, q /= g;
|
||||
|
||||
for (int i = 1; i * i <= q; i++) {
|
||||
if (q % i == 0) {
|
||||
long long a = i, b = q / i;
|
||||
|
||||
if (a * a + b * b == p) {
|
||||
cout << a << ' ' << b << endl;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << 0 << ' ' << 0 << endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
|
||||
cin >> t;
|
||||
|
||||
while (t--) solve();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user