QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793361 | #9622. 有限小数 | FHQY# | WA | 279ms | 3608kb | C++20 | 1.3kb | 2024-11-29 19:01:33 | 2024-11-29 19:01:34 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define R read()
#define ll __int128
#define endl '\n'
using namespace std;
inline ll read(){
ll x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-f;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10),x%=10;
putchar('0'+x);
}
inline void wk(ll x){write(x);putchar(' ');}
inline void we(ll x){write(x);putchar('\n');}
const ll lim=1e18,tim=1e9;
ll a,b;
ll fa2[100],fa5[100];
ll l,r;
ll ans,d;
void solve(){
a=R,b=R;
ans=(b-a),d=b;
ll t=1;
while(b%5==0)b/=5,t*=5;
while(b%2==0)b/=2,t%=2;
for(ll i=0;i<=l;i++){
for(ll j=0;j<=r;j++){
if(fa2[i]*fa5[j]>lim)break;
ll mul=fa2[i]*fa5[j];
if(mul%b==0){
ans=0;
break;
}
ll x=a*mul/b+1;
ll res=b*x-mul*a;
ll g=__gcd(b*mul,res);
res/=g;
if(b*mul/g<=tim){
if(ans>res)ans=res,d=b*mul/g;
}
}
}
wk(ans),we(d);
return ;
}
int T=1;
signed main(){
T=R;
ll t=1;
while(t<=lim){
fa2[l]=t;
t*=2;
l++;
}
l--;
t=1;
while(t<=lim){
fa5[r]=t;
t*=5;
r++;
}
r--;
// wk(l),we(r);
// cout<<l<<" "<<r<<endl;
for(int kase=1;kase<=T;kase++){
solve();
}
return 0;
}
/*
4
1 2
2 3
3 7
19 79
1
37 720896
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
4 1 2 2 3 3 7 19 79
output:
0 2 1 3 1 4375 3 316
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 279ms
memory: 3536kb
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 12 1 828125000 1 3 1 21875 1 231680000 23 960937500 1 36096000 5 326 1 63360 0 64 1 61000 0 32 1 4880 1 5375 1 9250 1 11714560 1 331250 1 898437500 1 31 1 6 1 289600000 1 455000 1 115000000 1 1265625 0 2 1 14843750 0 160 1 415 1 235937500 1 765000000 1 90625 1 2968750 1 4406250 3 6200 1 15 3 34750...
result:
wrong answer The result is not terminating.(Testcase 3)