제출 #374421

#제출 시각아이디문제언어결과실행 시간메모리
374421NONAMEEuklid (COCI20_euklid)C++17
35 / 110
800 ms520 KiB
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int gcd(int a, int b) {
    return (b == 0) ? a : gcd(b, a % b);
}

int r(int a, int b) {
    if (a < b) {
        swap(a, b);
    }
    if (b == 1) {
        return a;
    }
    return r(a / b, b);
}

void solve() {
    long long g, h;
    cin >> g >> h;

    // g = 1 + rnd() % 100;
    // h = 2 + rnd() % 100;
    // long long x = h / g * g;
    // cerr << g << " " << h << " " << r(h * g, x) << " " << gcd(h * g, x) << "\n";

    // assert((r(h * g, x) == h) && (gcd(h * g, x) == g));

    for (int i = 1; i <= 4000; ++i) {
        for (int j = 1; j <= 4000; ++j) {
            if ((r(i * g, j * g) == h) && (gcd(i, j) == 1)) {
                // cerr << (i * g) << " " << (j * g) << " " << i << " " << j << "\n";
                cout << (i * g) << " " << (j * g) << "\n";
                return;
            }
        }
    }
    assert(0);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...