Codeforces Round #426 (Div. 2) C - The Meaningless Game

一道大水题.
考虑到输入的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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值