QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745821#9622. 有限小数Chen1098TL 0ms0kbC++142.5kb2024-11-14 11:48:092024-11-14 11:48:09

Judging History

This is the latest submission verdict.

  • [2024-11-14 11:48:09]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-11-14 11:48:09]
  • Submitted

answer

#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,##__VA_ARGS__)
#define int long long
#define endl '\n'
#define pb push_back
#define pii pair<int,int>
using namespace std;
bool Men;
const int mod=998244353;
const int N=200005;

inline void write(int x){if(x<0) putchar('-'),x=-x;if(x>9) write(x/10);putchar(x%10+'0');return;}
inline int read() {int x=0,f=1; char ch=getchar();while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar();}while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
void add(int &x,int y){x=(x+y)%mod;}
int ksc(int m,int n,int p){int ans=0;while(n){if(n%2==1){n=n-1;ans=(ans+m)%p;}n=n/2;m=(m+m)%p;}return ans;}
int ksm(int base,int power,int p){int result=1;while(power>0){if(power&1){result=result*base%p;}power>>=1;base=(base*base)%p;}return result;}
int mod_inverse(int a){return ksm(a,mod-2,mod);}
int inv(int numerator,int denominator){int inverse_denominator = mod_inverse(denominator);int result=(1LL*numerator*inverse_denominator)%mod;return result;}
int a,b;
int FF;
int get(int i){
	if(!FF){
		i*=2,FF=1;
		return i; 
	}
	else{
		i*=5,FF=0;
		return i;
	}
	return i;
}
int g[1000000];
bool Mbe;
signed main(){
	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int T=read();
	int cnt=0;
	for(int i=0;i<=100000;i++){
		for(int j=0;j<=100000;j++){
			if(pow(2,i)*pow(5,j)>1e9) break;
			g[++cnt]=pow(2,i)*pow(5,j);
		}
	}
	sort(g+1,g+1+cnt);
	while(T--){
		a=read(),b=read();
		
		int tot=1,nowb=b,nowa=a;
		while(nowb%2==0){
			if(nowb%2!=0) break;
			nowb/=2; 
			tot*=2;
		}
		while(nowb%5==0){
			if(nowb%5!=0) break;
			nowb/=5;
			tot*=5;
		}
		int must=b/tot;
		if(tot!=1&&(a%must==0)){
			cout<<0<<' '<<1<<endl;
			continue;
		}
//		cout<<"SDF";
		int c=1e9,d=1e9;
		FF=1;
		for(int q=1;q<=cnt;q++){
			int i=g[q];
			if(b*i>=1e9) continue;
			int nowb=b*i,tot=1;
			while(nowb%2==0){
				if(nowb%2!=0) break;
				nowb/=2; 
				tot*=2;
			}
			while(nowb%5==0){
				if(nowb%5!=0) break;
				nowb/=5;
				tot*=5;
			}
			if(tot==1) continue;
//			cout<<"TOT "<<tot<<endl;
			//分子需要形成tot或者其倍数 
			int nowa=a*i;
			nowb=b*i;
			int must=nowb/tot;
			for(int j=(int)((nowa+must-1)/must);j<=((c+nowa)/must);j++){
				int nowmust=must*j;
				if(nowmust<=nowa) continue;
//				cout<<nowmust-nowa<<endl;
				if(nowmust-nowa<c){
					c=nowmust-nowa;
					d=nowb;
				}
				else continue;
			}
			if(c==1) break;
//			cout<<c<<endl;
		}
		cout<<c<<' '<<d<<endl;
	}
/*

2 5 

2
28 53
2 35


1
1
*/
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

4
1 2
2 3
3 7
19 79

output:


result: