QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#736993 | #9622. 有限小数 | monui | WA | 0ms | 3680kb | C++23 | 1.1kb | 2024-11-12 14:11:00 | 2024-11-12 14:11:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int INF=1e9;
int a,b;
int quick(int x,int n,int p){
int ans=1;
x%=p;
while(n){
if(n&1) ans=ans*x%p;
x=x*x%p;
n>>=1;
}
return ans;
}
int gcd(int x,int y){
if(!y) return x;
return gcd(y,x%y);
}
int exgcd(int a,int b,int& x,int& y){
if(!b){
x=1,y=0;
return a;
}
int d=exgcd(b,a%b,x,y);
int temp=x;
x=y;
y=temp-a/b*y;
return d;
}
void solve(){
cin>>a>>b;
int T=b;
while(T%2==0) T/=2;
while(T%5==0) T/=5;
if(T==1){
cout<<0<<" "<<1<<endl;
return;
}
int P=b/T;
int res_c=b-a,res_d=b;
for(int i=0,cur_1=1;i<1000&&cur_1*T<=INF;i++,cur_1*=2){
for(int j=0,cur_2=cur_1;j<1000&&cur_2*T<=INF;j++,cur_2*=5){
int temp=cur_2*a;
int x,y;
exgcd(P*temp,T*temp,x,y);
x=(x%T+T)%T*temp;
if(x<res_c){
res_c=x;
res_d=cur_2*T;
}
}
}
cout<<res_c<<" "<<res_d<<endl;
}
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int __T=1;
cin >> __T;
while (__T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3680kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 3 7 19 79
result:
wrong answer The result is not terminating.(Testcase 3)