40,求助
查看原帖
40,求助
528325
DHeasy楼主2022/3/31 18:02

QAQ超时“万岁”QAQ

#include<bits/stdc++.h>
#define ull unsigned long long
#define in int
#define d double
using namespace std;
int main()
{
	//freopen("math.in","r",stdin);
	//freopen("math.out","w",stdout);
	ull x,z,y;
	in t;
	cin>>t;
	for(in i=1;i<=t;i++){
		cin>>x>>z;
		if(z%x!=0){
			cout<<-1<<endl;
			continue;
		}
		ull c=0;
		for(ull j=x;j>=1;j--){
			if(x%j==0){
				c=j;
				ull y=z/x/c;
				if(y%c==0){
					break;
				}
				else{
					c=0;
				}
			}
		}
		if(c!=0){
			cout<<z/x/c<<endl;
		}
		else{
			cout<<-1<<endl;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

我照着题解打的,愿DL指点指点。

指点给关注

2022/3/31 18:02
加载中...