QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743868#9622. 有限小数WanShiWA 20ms3644kbC++141.8kb2024-11-13 20:12:192024-11-13 20:12:19

Judging History

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

  • [2024-11-13 20:12:19]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3644kb
  • [2024-11-13 20:12:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 2e5 + 5;
int __ = 1, n = 0, m;
string s;
int Exgcd(int a, int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = Exgcd(b, a % b, x, y);
    int t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
}
void solve()
{
    int a, b;
    cin >> a >> b;
    int L = 1e9;
    int w = b;
    while (w % 2 == 0)
        w /= 2;
    while (w % 5 == 0)
        w /= 5;
    int miy = 1e9, mix = 1e9;
    for (int i = w; i * 2 <= L; i *= 2)
    {
        for (int d = i; d * 5 <= L; d *= 5)
        {
            int x0, y0;
            int ta = b * d, tb = -b, tc = a * d;
            int g = Exgcd(ta, tb, x0, y0);
            // cerr << g << '\n';
            int x = x0 * tc / g;
            int y = y0 * tc / g;
            int dx = tb / g, dy = ta / g;

            // cerr << ta << " " << tb << " " << tc << '\n';
            // cerr << ta * x + tb * y << '\n';
            // cerr << dy << " " << y << '\n';
            if (y == 0)
            {
                miy = y;
                mix = d;
                continue;
            }
            int k = dy / y;

            // cerr << k << '\n';
            if (k != 0 && dy % k == 0)
            {
                if (-dy / k + y < miy)
                {
                    miy = -dy / k + y;
                    mix = d;
                }
            }
            // cerr << -dy / k + y << " " << d << '\n';
            // cerr << d << " " << x << " " << y << '\n';
        }
    }
    cout << miy << " " << mix << '\n';
    return;
}
int32_t main()
{
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cin >> __;
    while (__--)
        solve();
    return 0;
}

详细

Test #1:

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

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: 20ms
memory: 3644kb

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
25 53
0 3
0 14
11 1810
43 123
5 282
5 326
28 99
0 4
28 61
0 2
1000000000 1000000000
1000000000 1000000000
4 74
15 143
13 53
1000000000 1000000000
1 31
1 3
9 362
18 91
10 23
10 81
0 1
2 95
0 1
17 166
22 151
65 153
4 58
3 19
1000000000 1000000000
8 31
0 3
68 139
4 295
3 109
8 19
9 43
14 495
0 57
1...

result:

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