제출 #374461

#제출 시각아이디문제언어결과실행 시간메모리
374461VEGAnnEuklid (COCI20_euklid)C++14
75 / 110
454 ms512 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const ld E = 1e-9;
const int N = 2010;
int h, g;

int R(int a, int b){
    if (min(a, b) == 1) return max(a, b);

    if (b > a)
        return R(b / a, a);
    else return R(a / b, b);
}

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL


//    cerr << R(36, 130) << '\n';
//    cerr << R(38, 137) << '\n';
//    cerr << R(26, 91) << '\n';
//    cerr << R(28, 98) << '\n';
//    cerr << R(40, 120) << '\n';
//
//    return 0;

    int qq; cin >> qq;

    for (; qq; qq--){
        cin >> g >> h;

        if (h <= g){
            if (g == h){
                cout << g << " " << g << '\n';
                continue;
            }

            ll mx = 1;

            for (int i = g + g; ; i += g) {
                while (ll(mx) * ll(h) <= ll(i))
                    mx *= h;

                if (i / mx == 1) {
//                    cout << i << " " << i * h + g << '\n';
                    cout << ll(i) * ll(h) + ll(g) << " " << i << '\n';
                    break;
                }
            }

            continue;
        }

        int beg = g * ((h + g - 1) / g);

        for (int i = g; ; i += g)
            if (__gcd(i, beg) == g && R(i, beg) == h){
                cout << beg << " " << i << '\n';
                break;
            }
    }

    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...