QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740905#9622. 有限小数PHarrWA 0ms3760kbC++201.6kb2024-11-13 12:12:322024-11-13 12:12:32

Judging History

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

  • [2024-11-13 12:12:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3760kb
  • [2024-11-13 12:12:32]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i ++)
#define pre(i, l, r) for(int i = (l); i >= (r); i --)
#define Grp(x, i) for(int i = h[x]; i; i = ne[i])
using namespace std;

typedef long long LL;
const int N = 200009;

inline int read() {
    int x = 0; char fs = 0, c = getchar(); while(! isdigit(c)) fs |= (c == '-'), c = getchar();
    while(isdigit(c)) x = (x << 1) + (x << 3) + (c - '0'), c = getchar();
    return fs ? -x : x;
}

LL exgcd(LL a, LL b, LL &x, LL &y) {
    if(! b) return x = 1, y = 0, a;
    LL d = exgcd(b, a % b, x, y);
    LL z = x; x = y, y = z - y * (a / b);
    return d;
}

int a, b;
int B, T;

int main() {
    T = read();
    while(T --) {
        a = read(), b = read();
        B = b;
        while(B % 2 == 0) B >>= 1;
        while(B % 5 == 0) B /= 5;
        int x2 = 1;
        pair<LL, LL> ans(b - a, b);
        while(x2 <= (int)1e9 / B) {
            int x5 = 1;
            while(x5 <= (int)1e9 / x2 / B) {
                LL d = x5 * x2 * B;
                LL cc = 1ll * -d * a;
                LL aa = b;
                LL bb = 1ll * b * d;
                LL x = 0, y = 0;
                LL dd = exgcd(aa, bb, x, y);

                if(cc % dd == 0) {
                    LL p = bb / dd;
                    LL c = x * (cc / dd) % p;
                    c = (c + p) % p;
                    ans = min(ans, make_pair(c, d)); 
                }
                x5 *= 5;
            }
            x2 *= 2;
        }
        printf("%lld %lld\n", ans.first, ans.second);
    }
    return 0;
}

详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

1 2
1 3
4 7
60 79

result:

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