Submission #369602

#TimeUsernameProblemLanguageResultExecution timeMemory
369602penguinhackerEuklid (COCI20_euklid)C++14
12 / 110
1 ms492 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array ll R(ll a, ll b) { if (a < b) swap(a, b); if (b == 1) return a; return R(b, a / b); } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { ll a, b; cin >> a >> b; ll x = b, y = 1; int rep = 0; while(rep == 0 || (x * y + a - 1) / a * a >= (y + 1) * x) { y = (y + 1) * x - 1; swap(x, y); ++rep; } //cerr << x << " " << y << "\n"; y = (x * y + a - 1) / a * a; //cerr << x << " " << y << "\n"; x = x * y + a; //cerr << x << " " << y << "\n"; cout << x << " " << y << "\n"; assert(__gcd(x, y) == a); assert(R(x, y) == b); } 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...