QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#786403 | #9622. 有限小数 | EricW | WA | 3ms | 3680kb | C++14 | 1.1kb | 2024-11-26 21:23:02 | 2024-11-26 21:23:02 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int ans=1e17,ans1=0;
int max2=40,max5=40;
int tt=0;
void solve()
{
int a,b;
cin>>a>>b;
tt++;
if(tt==391)cout<<a<<" "<<b<<"\n";
if(tt>5)return ;
a=a%b;
int sum=1;
while(b%2==0)
{
sum*=2;
b/=2;
}
while(b%5==0)
{
sum*=5;
b/=5;
}
int temp=sum*b;
int temp1=sum*b;
for(int i=0;i<=max2;i++)
{
for(int j=0;j<=max5;j++)
{
int flag=0;
temp=sum*b;
for(int ii=1;ii<=i;ii++)
{
temp=temp*2;
if(temp>1e9)
{
flag=1;
break;
}
}
if(flag)
break;
for(int ii=1;ii<=j;ii++)
{
temp=temp*5;
if(temp>1e9)
{
flag=1;
break;
}
}
if(flag)
break;
int c=((-(temp/b/sum)*a)%b+b)%b;
if(c<ans)
{
ans=c;
ans1=temp;
}
}
}
cout<<ans/__gcd(ans,ans1)<<' '<<ans1/__gcd(ans,ans1)<<'\n';
}
signed main()
{
int t;
cin>>t;
while(t--)
{
ans=1e17;
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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: 3ms
memory: 3680kb
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 60 1 109375 1 231680000 51 166
result:
wrong answer The result is not terminating.(Testcase 6)