QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740626 | #9622. 有限小数 | PHarr | WA | 0ms | 3624kb | C++20 | 891b | 2024-11-13 10:47:13 | 2024-11-13 10:47:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 MAXN = 1e9;
const i64 inf = LLONG_MAX / 2;
i64 exgcd(i64 a, i64 b, i64 &x, i64&y) {
if(b == 0){
x = 1, y = 0;
return a;
}
i64 d = exgcd(b, a % b, y, x);
y -= a/ b * d;
return d;
}
i64 calc(i64 a, i64 b, i64 c) {
i64 x, y;
i64 d = exgcd(a, b, x, y);
if(c % d != 0) return inf;
x = x * c / d;
i64 t = b / d;
return (x % t + t) % t;
}
void solve() {
i64 a, b;
cin >> a >> b;
i64 w = b;
while(w % 2 == 0) w /= 2;
while(w % 5 == 0) w /= 5;
i64 resc = inf, resd;
for(i64 p5 = w; p5 <= MAXN; p5 *= 5)
for(i64 d = p5, c; d <= MAXN; d *= 2) {
c = calc(b, b * d, a * d);
if(c < resc) resc = c, resd = d;
}
cout << resc << " " << resd << "\n";
return;
}
int main() {
int T;
cin >> T;
while(T --)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
4 1 2 2 3 3 7 19 79
output:
1 2 2 3 3 7 19 79
result:
wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)