QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#739485 | #9622. 有限小数 | liubw_ | WA | 0ms | 3632kb | C++11 | 1.5kb | 2024-11-12 21:55:03 | 2024-11-12 21:55:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define int ll
const int inf=1E9+10;
void exgcd(int a,int b,int &x,int &y){
if(b==0){
x=1,y=0;
return;
}
exgcd(b,a%b,y,x);
y-=a/b*x;
}
int EXGCD(int a,int b,int c){ // ax+by==c 的最小正 x 解
// cerr<<"a="<<a<<" b="<<b<<" c="<<c<<'\n';
if(c<0) c+=(-(c/b)+1)*b;
// cerr<<"a="<<a<<" b="<<b<<" cc="<<c<<'\n';
int d=__gcd(a,b);
if(c%d!=0) return inf;
int x0,y0;
exgcd(a,b,x0,y0);
int alf=c/d,bta=(b/d);
// cerr<<" x00="<<x0<<'\n';
x0*=alf,y0*=alf;
// cerr<<" x01="<<x0<<'\n';
x0=(x0%bta+bta)%bta;
// cerr<<" x02="<<x0<<'\n';
return x0;
}
int qpow(int a,int b){
int ret=1;
while(b){
if(b&1) ret*=a;
a*=a;
b>>=1;
}
return ret;
}
void slv(){
int a,b,A,B;
cin>>a>>b;
A=1,B=b;
while(B%2==0){
A*=2;
B/=2;
}
while(B%5==0){
A*=5;
B/=5;
}
pair<int,int> ans=make_pair(inf,inf);
for(int x=0;x<=30;x++){
for(int y=0;y<=10;y++){
int C=a*qpow(2,x)*qpow(5,y);
pair<int,int> c=make_pair(EXGCD(A,B,-C),B*qpow(2,x)*qpow(5,y));
if(c.fr<=ans.fr) ans=c;
}
}
cout<<ans.fr<<' '<<ans.sc<<'\n';
return;
}
signed main(){
int T;
cin>>T;
while(T--) slv();
}
/*
4
1 2
2 3
3 7
19 79
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
4 1 2 2 3 3 7 19 79
output:
0 10485760000000000 1 31457280000000000 1 73400320000000000 3 6627000320000000
result:
wrong answer Integer 10485760000000000 violates the range [1, 10^9]