QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736993#9622. 有限小数monuiWA 0ms3680kbC++231.1kb2024-11-12 14:11:002024-11-12 14:11:01

Judging History

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

  • [2024-11-12 14:11:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-11-12 14:11:00]
  • 提交

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();
} 

詳細信息

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)