QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814581#9622. 有限小数kiana810WA 3ms3872kbC++141.4kb2024-12-14 18:35:122024-12-14 18:35:14

Judging History

This is the latest submission verdict.

  • [2024-12-14 18:35:14]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3872kb
  • [2024-12-14 18:35:12]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int T;
ll a, b, c, d;
int cp2, cp5;
ll ip2, ip5;

void exgcd(ll a, ll b, ll &x, ll &y) {
    if (!b) {
        x = 1ll;
        y = 0ll;
        return;
    }
    exgcd(b, a%b, x, y);
    ll t = x;
    x = y;
    y = t - a / b * y;
}

ll inv(ll a, ll p) {
    ll x, y;
    exgcd(a, p, x, y);
    x = (x % p + p) % p;
    return x;
}

int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%lld%lld", &a, &b);
        cp2 = cp5 = 0;
        for (; b % 2 == 0; b /= 2, cp2++);
        for (; b % 5 == 0; b /= 5, cp5++);
        if (b == 1) {
            puts("0 1");
            continue;
        }
        ip2 = ip5 = 1ll;
        for (int i = 0; i < cp2; i++, ip2 *= inv(2, b));
        for (int i = 0; i < cp5; i++, ip5 *= inv(5, b));
        c = 1e9 + 1ll;
        for (int i = 0; i < cp2 + 3; i++) {
            for (int j = 0; j < cp5 + 3; j++) {
                ll tmp = (-a % b + b) % b, tmp2 = b;
                for (int k = 0; k < i; k++, tmp *= 2, tmp %= b, tmp2 *= 2);
                for (int k = 0; k < j; k++, tmp *= 5, tmp %= b, tmp2 *= 5);
                if (tmp < c) {
                    c = tmp;
                    d = tmp2;
                }
            }
        }
        printf("%lld %lld\n", c, d);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 14
3 316

result:

ok 4 case(s)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3872kb

input:

10000
11 12
28 53
17 60
2 35
17 181
80 123
68 141
79 163
71 99
13 64
33 61
15 32
16 61
11 86
33 74
128 143
40 53
7 23
30 31
5 6
86 181
73 91
13 23
71 81
1 2
7 38
117 160
33 83
129 151
88 153
25 58
16 19
19 141
95 124
43 96
71 139
11 59
106 109
93 152
34 43
17 99
1 57
20 159
16 25
5 73
159 170
172 17...

output:

1 3
9 5300
1 3
1 70
11 1810
43 123
5 282
5 326
7 2475
0 1
11 1220
0 1
23 610
9 2150
3 370
7 1430
7 1325
9 575
1 31
1 3
9 362
18 91
4 115
7 2025
0 1
1 152
0 1
1 415
22 151
19 765
3 232
3 19
37 7050
3 6200
1 15
32 3475
4 295
3 109
1 190
2 215
14 495
7 2850
59 795
0 1
11 7300
1 17000
7 179
1 1300
1 425...

result:

wrong answer Jury found better answer than participant's 1 < 9 (Testcase 2)