Codeforces Round #426 (Div. 2) C

来源:互联网 发布:excel函数重复数据 编辑:程序博客网 时间:2024/06/07 09:41

一道大水题.
考虑到输入的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;}