#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |