QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#748921 | #9622. 有限小数 | kindow | WA | 24ms | 3892kb | C++20 | 1.1kb | 2024-11-14 21:58:44 | 2024-11-14 21:58:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
ll a, b;
cin >> a >> b;
vector<ll> mul2(30);
vector<ll> mul5(30);
vector<ll> mul10(30);
mul2[0] = mul5[0] = mul10[0] = 1;
ll m = max(ceil(log(b) / log(5)), ceil(log2(b)));
for(int i = 1; i <= m; ++i){
mul2[i] = mul2[i - 1] * 2ll;
mul5[i] = mul5[i - 1] * 5ll;
mul10[i] = mul10[i - 1] * 10ll;
}
ll miny = 0x7fffffffff;
ll totd;
for(ll i = 0; i <= m; ++i){
ll r = gcd(b, mul10[i]);
for(ll p = 0; p <= i; ++p){
for(ll q = 0; q <= i; ++q){
ll cur = mul10[i] / r * a / mul2[p] / mul5[q];
ll now = b / r;
ll bn = cur / now + 1;
ll c = (bn * now - cur) % now;
ll t = mul10[i] / mul2[p] / mul5[q];
ll curd = t * b / r;
if(c < miny){
miny = c;
totd = curd;
}
}
}
}
cout << miny << ' ' << totd << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
input:
4 1 2 2 3 3 7 19 79
output:
0 10 1 3 1 14 3 316
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 24ms
memory: 3892kb
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:
0 30 3 165625 0 12 0 14 7 90500 23 246000 5 282 5 326 1 63360 0 160 1 61000 0 1000 1 4880 1 10750 1 18500 3 28600000 1 331250 1 460000 1 31 0 15 7 113125 1 455000 3 92000 1 1265625 0 10 0 2375 0 400 1 415 1 235937500 1 765000000 1 4640 1 608 1 4406250 3 3100000 0 30000 3 347500 1 944 1 43600 0 23750...
result:
wrong answer The result is not terminating.(Testcase 1)