![](https://i-blog.csdnimg.cn/blog_migrate/263dfb5a9f0030e07e4b4af07533339c.png)
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
In the first string, the number of games n (1 ≤ n ≤ 350000) is given.
Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
6 2 4 75 45 8 8 16 16 247 994 1000000000 1000000
Yes Yes Yes No No Yes
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
题意:每局游戏胜者*k平方,败者*k,给出最后比分结果,判断是否合法。
题解:一开始想着两个数相除,一转念发现直接相乘的话,就是某数的k的三次方。昨天打到这里wa了五次。最后一分钟才想到比如1 64的情况,应该加一个两个数都能被这个开三次方的数整除,加上这个才是充分条件。第二天补题,莫名被long long卡了精度?
代码:
#include<bits/stdc++.h>
#define debug cout<<"aaa"<<endl
#define mem(a,b) memset(a,b,sizeof(a))
#define LL long long
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define MIN_INT (-2147483647-1)
#define MAX_INT 2147483647
#define MAX_LL 9223372036854775807i64
#define MIN_LL (-9223372036854775807i64-1)
using namespace std;
const int N = 100000 + 5;
const int mod = 1000000000 + 7;
LL a,b,n;
double num;
int t;
bool flag;
int main(){
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d",&a,&b);
num=a*b;
flag=0;
n=pow(num,1.0/3);
for(LL i=n-1;i<=n+1;i++){
if(i*i*i==a*b&&a%i==0&&b%i==0){//这里a*b换成num就错了,也不知道为什么。根据样例2调了一下才过
flag=1;
}
}
if(flag){
puts("Yes");
}
else{
puts("No");
}
}
return 0;
}