Submission #872173

#TimeUsernameProblemLanguageResultExecution timeMemory
872173SalihSahinEuklid (COCI20_euklid)C++14
75 / 110
736 ms516 KiB
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define int long long using namespace std; const int N = 4e6 + 5; const int mod = 1e9+7; const int inf = 1e18 + 10; const int L = 20 * 20 * 20; int gcd(int a, int b){ if(a < b) swap(a, b); if(b == 0) return a; return 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); } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--){ int g, h; cin>>g>>h; int a1 = 0, a2 = 0; for(int i = g; i <= N; i += g){ int l = i * h / g * g - g; for(int j = l; j < i * (h + 1); j += g){ if(gcd(i, j) == g && R(i, j) == h){ a1 = i, a2 = j; break; } } if(a1 > 0) break; } cout<<a1<<" "<<a2<<endl; } /* vector<pair<int, int> > test; vector<pair<int, int> > cantsolve; for(int i = 1; i < 50; i++){ for(int j = 2; j < 50; j++){ test.pb(mp(i, j)); } } for(auto itr: test){ int g = itr.first, h = itr.second; if(g == h){ continue; } int a = g * (h/g + (h%g ? 1 : 0)); int b = -1; for(int i = g; i <= N; i += g){ if(gcd(i, a) == g && r(i, a) == h){ b = i; break; } } if(b > 0) continue; cantsolve.pb(mp(g, h)); } for(auto itr: cantsolve){ int g = itr.first, h = itr.second; int a = -1, b = -1; for(int i = g; i <= N; i += g){ for(int j = i; j <= N; j += g){ if(gcd(i, j) == g && r(i, j) == h) a = i, b = j; if(a > 0) break; } if(a > 0) break; } cout<<g<<" "<<h<<" ans = "<<a<<" "<<b<<endl; } */ 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...