QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749420 | #9622. 有限小数 | wei177 | WA | 0ms | 3588kb | C++17 | 960b | 2024-11-15 00:36:02 | 2024-11-15 00:36:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll exgcd(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll cal(ll a, ll b, ll c) {
ll x, y;
ll d = exgcd(a, b, x, y);
if (c % d != 0) return 1e9;
x *= c / d;
return (x % (b / d) + (b / d)) % (b / d);
}
void slove() {
ll a, b;
cin >> a >> b;
ll w = b;
while (w % 2 == 0) w /= 2;
while (w % 5 == 0) w /= 5;
if (w == 1) {
cout << "0 1\n";
return;
}
ll ansc = 1e9, ansd = 1e9;
for (ll t1 = 1; w * t1 <= 1e9; t1 *= 2) {
for (ll t2 = 1; t1 * t2 * w <= 1e9; t2 *= 5) {
ll d = t1 * t2 * w;
ll c = cal(b, -w * w, a * d);
if (c < ansc) {
ansc = c;
ansd = d;
}
}
}
cout << ansc << ' ' << ansd << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) slove();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 -2 15 -6 35 -78 1975
result:
wrong answer Integer -2 violates the range [0, 10^9]