QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#793188#9621. 连方FHQY#RE 0ms0kbC++17939b2024-11-29 17:31:402024-11-29 17:31:47

Judging History

你现在查看的是最新测评结果

  • [2024-11-29 17:31:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-29 17:31:40]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define endl '\n'
using namespace std;
const ll lim=1e12,tim=1e9;
ll a,b;
ll fa2[100],fa5[100];
ll l,r;
ll ans,d;
void solve(){
	cin>>a>>b;
	ans=(b-a),d=b;
	for(ll i=0;i<=l;i++){
		for(ll j=0;j<=r;j++){
			if(fa2[i]*fa5[j]>lim)break;
			ll mul=fa2[i]*fa5[j];
			if(a*mul%b==0){
				ans=0;
				break;
			}
			ll x=a*mul/b+1;
			ll res=b*x-mul*a;
			ll g=__gcd(b*mul,res);
			res/=g;
			if(b*mul/g<=tim){
				if(ans>res)ans=res,d=b*mul/g;
			}
		}
	}
	cout<<ans<<" "<<d<<endl;
	return ;
}
int T=1;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>T;
	ll t=1;
	while(t<=lim){
		fa2[l]=t;
		t*=2;
		l++;
	}
	l--;
	t=1;
	while(t<=lim){
		fa5[r]=t;
		t*=5;
		r++;
	}
	r--;
//	cout<<l<<" "<<r<<endl;
	for(int kase=1;kase<=T;kase++){
		solve();
	}
	return 0;
}
/*
4
1 2
2 3
3 7
19 79
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

5
4
#..#
.##.
5
##.#.
.#.##
6
######
.####.
27
.######.######.####.#.#####
.####...####..#.......#####
10
##########
##########

output:


result: