QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#739810 | #9622. 有限小数 | MEshooter | WA | 0ms | 3644kb | C++20 | 1.4kb | 2024-11-12 23:15:35 | 2024-11-12 23:15:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3f3f3f3f;
ll two[100], five[100];
void init(){
two[0] = five[0] = 1;
for(int i = 1; i < 32 && two[i-1] < 1e18; i++)
two[i] = two[i-1]*2;
for(int i = 1; i < 32 && five[i-1] < 1e18; i++)
five[i] = five[i-1]*5;
}
ll sub(ll x){
while(x%2 == 0) x /= 2;
while(x%5 == 0) x /= 5;
return x;
}
ll exgcd(ll a, ll b, ll &x, ll &y){
if(!b){
x = 1; y = 0;
return a;
}
ll d = exgcd(b, a%b, x, y), t = x;
x = y;
y = t-a/b*y;
return d;
}
int main(){
ios :: sync_with_stdio(false);
init();
int T; cin >> T;
while(T--){
ll a, b, w, minc = INF, ans_d, ans_k;
cin >> a >> b;
w = sub(b);
for(int i = 0; i < 32 && w*two[i] <= 1e9; i++){
for(int j = 0; j < 32 && w*two[i]*five[j] <= 1e9; j++){
// w^2 * k - b * c = a*d;
ll d = w*two[i]*five[j], k, c;
exgcd(w*w, b, k, c);
ll t = max(-(a*d*k)/b+1, a*d*c/(w*w)+1);
c = -a*d*c/w+w*t;
k = a*d*k/w+b*t/w;
// cout << c << " " << t << endl;
if(c < minc) minc = c, ans_d = d, ans_k = k;
}
}
cout << minc << " " << ans_d << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3644kb
input:
4 1 2 2 3 3 7 19 79
output:
1 1 1 3 1 4375 3 316
result:
wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)