民间WA 求调
查看原帖
民间WA 求调
1564554
zai_shui_yi_xia楼主2025/1/26 20:15
#include<bits/stdc++.h>
using namespace std;
long long T,x,z,y,gcd,t;
bool b;
int main(){
	scanf("%lld",&T);
	while(T){
		T--;
		scanf("%lld%lld",&x,&z);
		if(z%x!=0){
			printf("-1\n");
			continue;
		}
		t=z/x;
		if(t==1){
			printf("1\n");
			continue;
		}
		gcd=__gcd(x*x,t);
		double hh=sqrt(gcd)*1.000000;
		if(hh*hh==gcd){
			y=t/hh;
			printf("%lld\n",y);
		}
		else printf("-1\n");
	}
	return 0;
}
2025/1/26 20:15
加载中...