QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#796737 | #9622. 有限小数 | AdisFD | WA | 0ms | 3656kb | C++14 | 1.1kb | 2024-12-02 01:11:59 | 2024-12-02 01:11:59 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,a,b,c,ans,ans1,ans2,gd1,k2,k5,a2,a5;
int i1,i2;
int gcd(int a1,int b1) {
int c1=a1%b1;
while(b1!=0) {
c1=a1%b1;
a1=b1;
b1=c1;
}
return a1;
}
int dfs(int a1,int b1,bool b2) {
int gd=1;
if(ans==1)return 0;
gd=gcd(c-(a1%c),b1);
if(b1/gd>1000000000)return 0;
if((c-(a1%c))/gd<ans) {
ans=(c-(a1%c))/gd;
ans1=b1/gd;
}
if(b2==0)dfs(a1*2,b1*2,0);
dfs(a1*5,b1*5,1);
return 0;
}
signed main() {
cin>>T;
for(int I=1; I<=T; I++) {
cin>>a>>b;
c=b;
k2=k5=0;
while(c%2==0) {
c/=2;
k2++;
}
while(c%5==0) {
c/=5;
k5++;
}
if(c==1) {
cout<<"0 1"<<endl;
continue;
}
ans=c+1;
// dfs(a,b,0);
a2=1;
for(int i=0; i<=k2; i++) {
a2*=2;
a5=1;
for(int ii=0; ii<=k5; ii++) {
a5*=5;
i1=a2*a5*c/10;
for(int j=1; j<c; j++) {
ans2=j*(b/i1)+a;
ans2=c-(ans2%c);
if(ans2==c) {
gd1=gcd(j,i1);
if(j/gd1<ans) {
ans=j/gd1;
ans1=i1/gd1;
}
}
}
}
}
cout<<ans<<" "<<ans1<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 4 7 60 79
result:
wrong answer Jury found better answer than participant's 1 < 4 (Testcase 3)