#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
using i64 = std::int64_t;
constexpr i64 ceil_div(const i64 a, const i64 b) {
return (a + b - 1) / b;
}
pair<i64, i64> solve(const i64 G, const i64 H) {
i64 low = 1, high = 1;
while (high - low + 1 < G) {
low = low * H + 0;
high = high * H + (H - 1);
}
i64 a = ceil_div(low, G) * G, b = H;
return {a, a * b + G};
}
i64 edicul(const i64 a, const i64 b) {
if (a < b) return edicul(b, a);
if (b == 1) return a;
return edicul(a / b, b);
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int Q;
std::cin >> Q;
while (Q--) {
i64 G, H;
std::cin >> G >> H;
const auto [a, b] = solve(G, H);
assert(std::gcd(a, b) == G);
assert(edicul(a, b) == H);
std::cout << a << ' ' << b << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |