T2乱搞,大样例全过,求hack
查看原帖
T2乱搞,大样例全过,求hack
203557
Wither_Zilla楼主2022/3/26 18:15
#include<bits/stdc++.h>
#define int long long
using namespace std;
int r()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		x=x*10+(ch^48),ch=getchar();
	return x*f;
}
// T->5e5  x->1e9   z->2^63
int gcd(int x,int y)
{
	while(x^=y^=x^=y%=x);
	return y;
}
bool check(int x)
{
	int t=(double)(sqrt(x)*10000);
	if(t%10000!=0)
		return true;
	else
		return false;
}
signed main()
{
//	freopen("math.in","r",stdin);
//	freopen("math.out","w",stdout);
	int T=r(),x,z;
	while(T--)
	{
		x=r(),z=r();
		if(z%x!=0)
		{
			puts("-1");
			continue;
		}
		z/=x;
		int t=z/gcd(x,z);
		if(z%x==0&&z/x!=1||z!=1&&z/gcd(x,z)==1&&check(z))
			puts("-1");
		else
		{
			if(t*gcd(x,t)==z)
				printf("%lld\n",t);
			else
			{
				t*=sqrt(z/(t*gcd(x,t)));
				if(t*gcd(x,t)==z)
					printf("%lld\n",t);
				else
					printf("%lld\n",z);
			}		
		}		
	}
	return 0;
}

RtRt,求 HackHack

2022/3/26 18:15
加载中...