QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#716219#6440. Xingqiu's JokelamkappaWA 192ms3816kbC++201.7kb2024-11-06 14:41:322024-11-06 14:41:38

Judging History

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

  • [2024-11-06 14:41:38]
  • 评测
  • 测评结果:WA
  • 用时:192ms
  • 内存:3816kb
  • [2024-11-06 14:41:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
using i64 = long long;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; cin >> T;
    while(T--){
        int a, b; cin >> a >> b;
        if(a > b) swap(a, b);
        int c = b - a;

        if(c == 0){
            int ans = 0;
            for(int x = 2; x * x <= a; x++){
                while(a % x == 0){
                    a /= x;
                    ans++;
                }
            }
            if(a > 1) ans++;
            cout << ans << '\n';
            continue;
        }else if(c == 1){
            cout << a - 1 << '\n';
            continue;
        }

        vector<int> fac;
        for(int x = 2; x * x <= c; x++){
            if(c % x == 0){
                fac.push_back(x);
                while(c % x == 0) c /= x;
            }
        }
        if(c > 1) fac.push_back(c);

        unordered_set<int> vis;
        using Node = tuple<int, int, int>;
        priority_queue<Node, vector<Node>, greater<>> q;
        q.emplace(0, a, b);
        while(!q.empty()){
            auto[d, u, v] = q.top(); q.pop();
            if(u == 1){
                cout << d << '\n';
                break;
            }
            if(vis.count(u)) continue;
            vis.insert(u);
            q.emplace(d + u - 1, 1, v - u + 1);
            for(auto p : fac){
                if((u - v) % p != 0) continue;
                
                auto x = u % p;
                if((u - x) / p > 0) q.emplace(d + x + 1, (u - x) / p, (v - x) / p);
                
                x = p - u % p;
                q.emplace(d + x + 1, (u + x) / p, (v + x) / p);
            }
        }
    }
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

5
4 7
9 8
32 84
11 35
2 1

output:

2
7
5
4
0

result:

ok 5 number(s): "2 7 5 4 0"

Test #2:

score: -100
Wrong Answer
time: 192ms
memory: 3724kb

input:

300
223528529 446621399
755625805 978718675
257717538 480810408
277875777 54782907
963091558 739998688
282469431 505562301
38752451 261845321
474429597 697522467
67026335 290119205
874629705 651536835
301964126 78871256
316864911 93772041
545942587 322849717
640801578 417708708
683070559 906163429
9...

output:

12
19
15
17
16
17
13
19
15
17
15
15
18
17
17
19
14
18
15
16
17
18
19
15
17
17
17
12
19
16
12
19
16
15
13
18
17
18
16
15
14
17
14
16
15
14
19
18
16
14
16
17
16
18
14
16
17
14
18
17
16
19
19
18
17
16
16
14
23
14
14
18
18
20
16
16
17
17
12
18
19
17
16
18
16
15
18
12
15
18
16
12
19
18
15
18
17
14
13
16
...

result:

wrong answer 161st numbers differ - expected: '14', found: '15'