QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737340 | #9622. 有限小数 | hezlik# | WA | 75ms | 3672kb | C++20 | 1.2kb | 2024-11-12 15:33:03 | 2024-11-12 15:33:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=32;
const long long inf=1e9;
long long A[N][N],C,D;
void exgcd(long long a,long long b,long long &x,long long &y){
if(!b){
x=1,y=0; return;
}
exgcd(b,a%b,y,x);
y-=(a/b)*x;
}
void solve(){
int a,b,t;
cin>>a>>b,t=b;
int k=b;
while(k%2==0) k/=2;
while(k%5==0) k/=5;
if(k==1){
cout<<0<<" "<<1<<'\n'; return;
}
C=1e18,D=0;
for(int i=0;i<=30;i++)
for(int j=0;j<=30;j++){
if(A[i][j]*k>inf||A[i][j]*k<0) break;
int x1=A[i][j]%k*a%k;
int x2=t/k;
int res=k-x1;
long long Y,Z;
exgcd((x2)%k,k,Y,Z);
// if(i==0&&j==0)
// cout<<k<<"ssss"<<","<<Y<<","<<res<<","<<Z<<endl;
Y=(Y%k+k)%k;
Y=Y*res%k;
if(C>Y){
C=Y,D=A[i][j]*k;
}
}
cout<<C<<" "<<D<<'\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T; cin>>T;
A[0][0]=1;
for(int i=0;i<=30;i++)
for(int j=0;j<=30;j++){
if(i+j==0) continue;
if(i>=1) A[i][j]=A[i-1][j]*2;
else A[i][j]=A[i][j-1]*2;
if(A[i][j]<0||A[i][j]>inf) A[i][j]=-1;
}
while(T--) solve();
}
// 4
// 1 2
// 2 3
// 3 7
// 19 79
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 1 14 3 316
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 75ms
memory: 3672kb
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 3 1 54272 1 6 1 7 31 2965504 23 3936 5 282 5 326 5 3168 0 1 1 31232 0 1 7 1998848 1 44032 2 37 15 143 5 444596224 1 2944 1 31 1 6 9 362 9 186368 5 23552 10 81 0 1 1 304 0 1 3 10878976 11 2473984 5 156672 2 29 1 608 1 72192 15 31 1 3 15 36438016 1 944 3 109 1 76 7 22016 1 6336 1 29184 19 2605056 0 ...
result:
wrong answer Jury found better answer than participant's 1 < 31 (Testcase 5)