RE求助
查看原帖
RE求助
310790
RYANGSJ楼主2022/3/27 13:01

85分,RE了1 2 3三个点

代码

#include<bits/stdc++.h>
#define int long long
#define _end putchar('\n')
using namespace std;
int n;
int read(){
	char ch=getchar();
	int f=1,res=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		res*=10;
		res+=(ch-'0');
		ch=getchar();
	}
	return res*f;
}
void write(int x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<=9){
		putchar(x+'0');
	}else{
		write(x/10);
		putchar(x%10+'0');
	}
}
int gcd(int x,int y){
	if(x%y==0)return y;
	return gcd(y,x%y);
}
signed main(){
	n=read();
	for(int i=1;i<=n;i++){
		int x=read();
		int z=read();
		int ycd=z/x;
		int ggcd=gcd(x,ycd);
		int y=z/ggcd/x;
        y*=sqrt(z/x/y/gcd(x,y));
        if(x*y*gcd(x,y)!=z)write(-1);
        else  write(y);
		_end;
	}
	return 0;
} 
2022/3/27 13:01
加载中...