一道大水题.
考虑到输入的a,b,得到一个g=gcd(a,b),令x=a/g,y=b/g,x,y一定是互质的,而且x|g,y|g,令g/=(x*y)后一定是一个数的三次方,考虑到a, b<1e9,打个1000的表lower_bound一下就可以了
#include<cstdio>
#include<iostream>
#include<algorithm>
const int N = 1111;
using namespace std;
int x3[N];
int gcd(int a, int b){
return b?gcd(b,a%b):a;
}
void init(){
for(int i = 0; i < 1111; i++){
x3[i]=i*i*i;
}
}
bool judge(int a){
int pos = lower_bound(x3,x3+1111,a)-x3;
//cout << x3[pos]<<endl;
if(x3[pos]!=a)return true;
return false;
}
int main(){
init();int t,a,b;scanf("%d",&t);
while(t--){
bool flag = 0;
scanf("%d%d",&a,&b);
int g = gcd(a,b);
int x = a/g;
int y = b/g;
if(g%x!=0)flag=1;
else{
g/=x;
if(g%y!=0)flag=1;
else {
g/=y;
if(judge(g)){
flag = 1;
}
}
}
if(flag)puts("No");
else puts("Yes");
}
return 0;
}