QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743081#9622. 有限小数chatoyaneWA 0ms3600kbC++201.3kb2024-11-13 18:10:322024-11-13 18:10:33

Judging History

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

  • [2024-11-13 18:10:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2024-11-13 18:10:32]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using LL = long long;
using db = double;
#define endl '\n'

const LL inf = 1e18;

void solve()
{
    LL a, b;
    cin >> a >> b;

    auto check = [&](int x) -> bool
    {
        while (x % 2 == 0)
            x /= 2;
        while (x % 5 == 0)
            x /= 5;
        return (x == 1);
    };

    if (check(b))
    {
        cout << "0 1" << endl;
        return;
    }

    LL d = b;
    while (d % 2 == 0)
        d /= 2;
    while (d % 5 == 0)
        d /= 5;

    LL ans1 = 1e18, ans2 = 1e18;
    for (LL pw2 = 1; pw2 * b <= 1e18; pw2 *= 2)
    {
        for (LL pw5 = 1; pw5 * pw2 * b <= 1e18; pw5 *= 5)
        {
            LL k = pw2 * pw5;
            LL c = (d - (a * k) % d) % d;
            LL g = gcd(c, b * k);
            LL c1 = c / g, d1 = b * k / g;
            if (c1 < ans1)
            {
                ans1 = c1, ans2 = d1;
            }
            // ans = min(ans, c);
        }
    }
    // if (ans1 == 193)
    // {
    //     cerr << "a = " << a << " b = " << b << endl;
    // }
    // if (ans1 == 193)
    //     cout << a << endl;

    cout << ans1 << " " << ans2 << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3600kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 4375
3 1506805419921875

result:

wrong answer Integer 1506805419921875 violates the range [1, 10^9]