QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791905#9622. 有限小数UESTC_DECAYALI#WA 0ms3512kbC++201.4kb2024-11-28 21:52:032024-11-28 21:52:27

Judging History

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

  • [2024-11-28 21:52:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3512kb
  • [2024-11-28 21:52:03]
  • 提交

answer

#include <bits/stdc++.h>

using i128 = __int128_t;
using llsi = long long;

i128 p2[41] = {1}, p5[41] = {1};
i128 w;

i128 exgcd(i128 a, i128 b, i128 &x, i128 &y) {
    if (0==b) { x = 1; y = 0; return a; }
    i128 ret = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return ret;
}

i128 calc(i128 a, i128 b, i128 c) {
    i128 x0, y0;
    i128 g = exgcd(a, b, x0, y0);
    // assert(a * x0 + b * y0 == g);
    if (c % g != 0) return -1;
    x0 *= c / g, y0 *= c / g;
    i128 val = abs(llsi(b / g));
    x0 = (x0 % val + val) % val;
    if (0 == x0) x0 = val;
    return x0;
}

void work() {
    llsi a, b; std::cin >> a >> b;
    llsi c, d = -1;
    for(int x = 0; x <= 30; ++x) for(int y = 0; y <= 13; ++y) {
        if(b * w % (p2[x] * p5[y]) != 0) break;
        llsi nd = b * w / (p2[x] * p5[y]), nc = calc(- p2[x] * p5[y], b, a * w);
        if(nc < 0) continue;
        if(nd > 1'000'000'000) continue;
        // std::cerr << std::format("x = {}, y = {}, c = {}, d = {}\n", p2[x], p5[y], nc, nd);
        if(d < 0 || nc < c) c = nc, d = nd;
    }

    std::cout << c << " " << d << std::endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    for(int i = 1; i <= 40; ++i) p2[i] = p2[i - 1] * 2, p5[i] = p5[i - 1] * 5;
    w = p2[2] * p5[2];
    // std::cout << llsi(w) << char(10);
    int T; std::cin >> T; while(T--) work();
    return 0;
}

详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

1 100
1 300
1 700
3 316

result:

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