QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808225#9868. GCDhyjhyj111TL 0ms0kbC++20894b2024-12-10 18:18:472024-12-10 18:18:47

Judging History

你现在查看的是最新测评结果

  • [2024-12-10 18:18:47]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [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

output:


result: