Submission #1047826

#TimeUsernameProblemLanguageResultExecution timeMemory
1047826FzArKEuklid (COCI20_euklid)C++17
75 / 110
1 ms604 KiB
#include<bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define sz(x) (int) x.size() #define all(x) x.begin(), x.end() #define FAST ios::sync_with_stdio(0); cin.tie(0); #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define random mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnd(time(0)); const int INF = 1e9; const int MX = 2e5 + 9; const int MOD = 1e9 + 7; //const int MOD = 998244353; void solve() { ll g, h; cin >> g >> h; ll x = h, y = 1; while (y <= g) { if (x > y) { swap(x, y); } else { x = min((x * y + g - 1) / g * g, (x + 1) * y - 1); } } if (y % g) { if (x > y) { swap(x, y); } x = (x * y + g - 1) / g * g; } {// make gcd = g if (x > y) { swap(x, y); } x = x * y + g; } assert (__gcd(x, y) == g); cout << x << " " << y << endl; } int main() { FAST; int t = 1; cin >> t; while (t--) { solve(); } } /* */
#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...