CodeForces 834C

/*
CodeForces 834C - The Meaningless Game [ 分析,数学 ]  |  Codeforces Round #426 (Div. 2) 
题意:
	一对数字 a,b 能不能被表示为 a = x^2 * y , b = x * y^2
分析:
	看出题意就差不多可以直接上了
	a^2 = x^4 * y^2  , b = x * y^2
	x^3 = a^2/b
	同理
	y^3 = b^2/a
	随便验证一下,开三次方这个,要么预打表,要么pow() 完微调
*/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL a, b, aa, bb;
int n;
bool flag;
int main()
{
    scanf("%d", &n);
    while (n--)
    {
        scanf("%lld%lld", &a, &b);
        aa = a*a; bb = b*b;
        if (aa%b || bb % a)
        {
            puts("No"); continue;
        }
        LL x = pow(aa/b, 1./3);
        while (x*x*x > aa/b) --x;
        while ((x+1)*(x+1)*(x+1) <= aa/b) ++x;
        if (x*x*x != aa/b)
        {
            puts("No"); continue;
        }
        LL y = pow(bb/a, 1./3);
        while (y*y*y > bb/a) --y;
        while ((y+1)*(y+1)*(y+1) <= bb/a) ++y;
        if (y*y*y != bb/a)
        {
            puts("No"); continue;
        }
        if (x*x*y != a || x*y*y != b) puts("No");
        else puts("Yes");
    }
}

  

我自倾杯,君且随意
原文地址:https://www.cnblogs.com/nicetomeetu/p/7265177.html