From 394dec7271d5e02dbb83109458edb73b4777ea9f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 16 Feb 2023 17:25:49 +0800 Subject: [PATCH] =?UTF-8?q?#1929.=20=E3=80=90Gym103446D=E3=80=91Strange=20?= =?UTF-8?q?Fractions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/70572 --- S2OJ/1929/1929.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 S2OJ/1929/1929.cpp diff --git a/S2OJ/1929/1929.cpp b/S2OJ/1929/1929.cpp new file mode 100644 index 00000000..4c974ec0 --- /dev/null +++ b/S2OJ/1929/1929.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +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; +}