QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#814585 | #9622. 有限小数 | kiana810 | WA | 110ms | 3944kb | C++14 | 1.5kb | 2024-12-14 18:38:50 | 2024-12-14 18:38:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int T;
ll a, b, c, d;
int cp2, cp5;
ll ip2, ip5;
void exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1ll;
y = 0ll;
return;
}
exgcd(b, a%b, x, y);
ll t = x;
x = y;
y = t - a / b * y;
}
ll inv(ll a, ll p) {
ll x, y;
exgcd(a, p, x, y);
x = (x % p + p) % p;
return x;
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%lld%lld", &a, &b);
cp2 = cp5 = 0;
for (; b % 2 == 0; b /= 2, cp2++);
for (; b % 5 == 0; b /= 5, cp5++);
if (b == 1) {
puts("0 1");
continue;
}
ip2 = ip5 = 1ll;
for (int i = 0; i < cp2; i++, ip2 *= inv(2, b));
for (int i = 0; i < cp5; i++, ip5 *= inv(5, b));
c = 1e9 + 1ll;
for (int i = 0; i < 35; i++) {
for (int j = 0; j < 15; j++) {
ll tmp = (-a % b + b) % b, tmp2 = b;
for (int k = 0; (k < i) && (tmp2 <= 1e9); k++, tmp2 *= 2);
for (int k = 0; (k < j) && (tmp2 <= 1e9); k++, tmp2 *= 5);
if (tmp2 > 1e9) continue;
for (int k = 0; k < i; k++, tmp *= 2, tmp %= b);
for (int k = 0; k < j; k++, tmp *= 5, tmp %= b);
if (tmp < c) {
c = tmp;
d = tmp2;
}
}
}
printf("%lld %lld\n", c, d);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3944kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 1 4375 3 316
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 110ms
memory: 3844kb
input:
10000 11 12 28 53 17 60 2 35 17 181 80 123 68 141 79 163 71 99 13 64 33 61 15 32 16 61 11 86 33 74 128 143 40 53 7 23 30 31 5 6 86 181 73 91 13 23 71 81 1 2 7 38 117 160 33 83 129 151 88 153 25 58 16 19 19 141 95 124 43 96 71 139 11 59 106 109 93 152 34 43 17 99 1 57 20 159 16 25 5 73 159 170 172 17...
output:
1 3 1 828125000 1 3 1 21875 1 231680000 23 960937500 1 36096000 5 326 1 63360 0 1 1 61000 0 1 1 4880 1 5375 1 9250 1 11714560 1 331250 1 898437500 1 31 1 3 1 289600000 1 455000 1 115000000 1 1265625 0 1 1 14843750 0 1 1 415 1 235937500 1 765000000 1 90625 1 2968750 1 4406250 3 6200 1 15 3 347500 1 9...
result:
wrong answer The result is not terminating.(Testcase 3)