QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740905 | #9622. 有限小数 | PHarr | WA | 0ms | 3760kb | C++20 | 1.6kb | 2024-11-13 12:12:32 | 2024-11-13 12:12:32 |
Judging History
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)