QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739390#9622. 有限小数qzhfxWA 22ms3592kbC++232.0kb2024-11-12 21:38:382024-11-12 21:38:43

Judging History

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

  • [2024-11-12 21:38:43]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:3592kb
  • [2024-11-12 21:38:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 7;
const int mod = 998244353;
const int L = 1e9;
// #define ll __int128
// 求解不定方程 ax+by=c 的最小整数解 x
ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll ans = exgcd(b, a % b, x, y);
    ll tmp = x;
    x = y;
    y = tmp - a / b * y;
    return ans;
}
ll x, y;
ll cal(ll a, ll b, ll c)
{
    x = 0, y = 0;
    ll ans = exgcd(a, b, x, y);
    if (c % ans)
        return -1;
    x *= c / ans;
    b /= ans;
    // y *= c / ans;
    if (b < 0)
        b = -b;
    x = (x % b + b) % b;
    return x;
}
std::vector<ll> px;
void solve()
{
    int a, b;
    cin >> a >> b;
    ll p = b, k = 1;
    while (p % 2 == 0)
    {
        p /= 2;
        k *= 2;
    }
    while (p % 5 == 0)
    {
        p /= 5;
        k *= 5;
    }
    long long c = 1e18, t = 0;
    auto check = [&](ll id)
    {
        c = cal(k, p, - a * id);
    };
    ll d = 1;
    ll cx = 1e18, ct = 0;
    for (auto pd : px)
    {
        // cerr << pd << '\n';
        ll s = pd;
        check(s);
        if (c >= 0 && cx > c && d * p <= L)
        {
            // cerr << pd << " " << c << '\n';
            cx = c;
            d = pd;
        }
    }
    cout << cx << " " << d * p << '\n';
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // px.push_back(1);
    for (int i = 0;; i++)
    {
        ll now = 1;
        int x = i;
        while (x--)
        {
            now *= 2;
        }
        if (now > L)
            break;
        for (int j = 0;; j++)
        {
            int y = j;
            while (y--)
            {
                now *= 5;
            }
            if (now > L)
                break;
            px.push_back(now);
        }
    }
    sort(px.begin(), px.end());
    int _ = 1;
    cin >> _;
    while (_--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 22ms
memory: 3592kb

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
1 54272
1 6
1 7
7 90500
23 3936
1 36096000
4 1591796875
1 63360
0 1
1 31232
0 1
1 4880
1 10750
1 18500
1 11714560
1 53000000
1 2944
1 31
1 6
5 1448000000
8 888671875
1 58880
1 51840
0 1
1 304
0 1
1 415
1 19328000
1 20054016000
1 4640
1 608
1 72192
11 1240
1 3
9 1112000000
1 944
3 109
1 76
1 1761...

result:

wrong answer Jury found better answer than participant's 1 < 7 (Testcase 5)