This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |