QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661853#6440. Xingqiu's Jokewxy3265WA 598ms4640kbC++141.9kb2024-10-20 18:30:332024-10-20 18:30:38

Judging History

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

  • [2024-10-20 18:30:38]
  • 评测
  • 测评结果:WA
  • 用时:598ms
  • 内存:4640kb
  • [2024-10-20 18:30:33]
  • 提交

answer

//
// Created by wxy3265 on 2024/10/20.
//

#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#define int long long
using namespace std;

struct Status{
    int a, b, step;
};

const int MAXP = 1e5 + 3;
int v[MAXP], prime[MAXP];
int cnt;
void primes(int n) {
    cnt = 0;
    for (int i = 2; i <= n; i++) {
        if (!v[i]) {
            v[i] = i;
            prime[++cnt] = i;
        }
        for (int j = 1; j <= cnt; j++) {
            if (prime[j] > v[i] || prime[j] > n / i) break;
            v[i * prime[j]] = prime[j];
        }
    }
}

int d[MAXP];
int tot;
map<pair<int, int>, int> mp;

void dfs(int a, int b) {
    if (mp.count(make_pair(a, b))) return;
    if (a - b == 1) {
        mp[make_pair(a,b)] = b - 1;
        return;
    }
    if (b == 1) {
        mp[make_pair(a, b)] = 0;
        return;
    }
    mp[make_pair(a, b)] = b - 1;
    for (int i = 1; i <= tot; i++) {
        int p = d[i];
        if ((a - b) % p == 0) {
            int step1 = b % p;
            int step2 = p - step1;
            dfs((a - step1) / p, (b - step1) / p);
            mp[make_pair(a, b)] = min(mp[make_pair(a, b)], mp[make_pair((a - step1) / p, (b - step1) / p)] + step1 + 1);
            int ba = (a + step2) / p, bb = (b + step2) / p;
            dfs(ba,  bb);
            mp[make_pair(a, b)] = min(mp[make_pair(a, b)], mp[make_pair(ba, bb)] + step2 + 1);
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    primes(1e5);
    int t;
    cin >> t;
    while (t--) {
        tot = 0;
        mp.clear();
        int x, y;
        cin >> x >> y;
        if (x < y) swap(x, y);
        int del = x - y;
        for (int i = 1; i <= cnt && prime[i] <= del; i++) {
            if (del % prime[i] == 0) d[++tot] = prime[i];
        }
        dfs(x, y);
        cout << mp[make_pair(x, y)] << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4596kb

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: 0
Accepted
time: 598ms
memory: 4608kb

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:

ok 300 numbers

Test #3:

score: 0
Accepted
time: 12ms
memory: 4564kb

input:

300
636099362 669653794
640628976 607074544
492031079 458476647
420324662 386770230
234845232 201290800
416098756 382544324
513320531 546874963
245050186 278604618
688926901 722481333
458533405 424978973
863331691 896886123
638892374 672446806
849746534 816192102
761591596 728037164
369934525 403488...

output:

51
49
48
45
35
45
50
42
53
47
61
53
59
55
43
41
53
55
44
62
48
39
36
60
40
55
49
54
50
38
59
41
39
43
47
57
54
50
52
39
54
52
39
37
32
34
56
38
53
41
51
50
55
56
35
44
35
45
59
33
53
59
56
57
43
53
54
45
34
58
33
55
56
33
46
49
33
38
38
55
54
47
56
47
52
60
36
53
56
53
44
43
34
59
55
49
52
40
35
55
...

result:

ok 300 numbers

Test #4:

score: -100
Wrong Answer
time: 17ms
memory: 4640kb

input:

300
867787179 877654074
403881553 407432589
201172453 192754452
822066929 815320907
516801596 518734008
278735158 276997924
39842929 46406996
229923235 222281597
958111516 962220928
514454467 511546909
66273896 56535006
603599579 602886043
99119397 89783150
606236932 603774684
948362977 945928285
92...

output:

57852482
100970390
192754451
170
484
187
847727
1359
79842629
28419277
18
1664
2186
277
1043
2411
227
35351414
60
367
572
986764287
863
122
222
2212
1989
793976084
1651
209
100
122
19089139
245
213
309355254
1028
503736315
858
77
6974
1773
83
197
16962
21101993
310
452
70
1626
6182341
160
1805
1556
...

result:

wrong answer 1st numbers differ - expected: '33397', found: '57852482'