QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#808225 | #9868. GCD | hyjhyj111 | TL | 0ms | 0kb | C++20 | 894b | 2024-12-10 18:18:47 | 2024-12-10 18:18:47 |
answer
#include <bits/stdc++.h>
using i64 = long long;
consteval auto operator"" _f(const char* str, std::size_t len) {
return [fmt = std::string_view(str, len)](auto&&... args) {
return std::vformat(fmt, std::make_format_args(args...));
};
}
void solve() {
i64 a, b;
std::cin >> a >> b;
int ans = 100;
auto dfs = [&](auto &&self, i64 a, i64 b, int cur) -> void {
if (a == 0 || b == 0) {
ans = std::min(ans, cur + 1);
return;
}
// if (cur > ans) return;
i64 g = std::gcd(a, b);
self(self, a - g, b, cur + 1);
self(self, a, b - g, cur + 1);
};
dfs(dfs, a, b, 0);
std::cout << ans << "\n";
}
signed main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int _ = 1;
std::cin >> _;
while (_ --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 3 4 12 20 114 514