제출 #342396

#제출 시각아이디문제언어결과실행 시간메모리
342396limabeansEuklid (COCI20_euklid)C++17
20 / 110
61 ms620 KiB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());




ll R(ll a, ll b) {
    if (a<b) swap(a,b);
    if (b==1) return a;
    return R(a/b, b);
}




void solve1(ll g, ll h) {
    assert(g==h);
    cout<<g<<" "<<g*g<<"\n";
}


void solve2(ll g, ll h) {
    assert(h==2);
    cout<<2*g<<" "<<g<<"\n";
}


void solve3(ll g, ll h) {
    assert(g==h*h);

    ll a = g*h;
    ll b = g;
    assert(R(a,b)==h);
    cout<<a<<" "<<b<<"\n";    
}

void solve(ll g, ll h) {
    for (int x=1; x<=1000; x++) {
	for (int y=1; y<=1000; y++) {
	    if (__gcd(x,y)==g && R(x,y)==h) {
		cout<<x<<" "<<y<<"\n";
		return;
	    }
	}
    }
    assert(false);
}


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


    int t;
    cin>>t;
    while (t--) {
	ll g,h;
	cin>>g>>h;
	
	if (g==h) {
	    solve1(g,h);
	} else if (h==2) {
	    solve2(g,h);
	} else if (g==h*h) {
	    solve3(g,h);    
	} else {
	    solve(g,h);
	}
    }
    
    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...