QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808895#9868. GCDYUKIIRE 0ms0kbC++14950b2024-12-11 09:23:142024-12-11 09:23:22

Judging History

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

  • [2024-12-11 09:23:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-12-11 09:23:14]
  • 提交

answer

#include <iostream>
#include <queue>
#include <random>

using namespace std;

uint64_t gcd(uint64_t a, uint64_t b) {
    uint64_t t;
    t = a % b;
    while (t)
        a = b, b = t, t = a % b;
    return b;
}

struct Pair {
    uint64_t a, b;
    int d;
};

int bfs(uint64_t const& a, uint64_t const& b) {
    queue<Pair> q;
    q.push({ a, b, 0 });
    while (true) {
        Pair& p = q.front();
        if (p.a % p.b == 0) {
            return p.d + 2;
        }
            
        uint64_t x = gcd(p.a, p.b);
        q.push({ p.a / x - 1, p.b / x, p.d + 1 });
        q.push({ p.a / x, p.b / x - 1, p.d + 1 });
        q.pop();
    }
    return 0;
}

int main() {
    int n;
    uint64_t a, b;
    cin >> n;
    for (int i = 0; i < 1000; ++i) {
        if (b < a) {
            cout << bfs(a, b) << endl;
        } else {
            cout << bfs(b, a) << endl;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
3 4
12 20
114 514

output:


result: