C

来源:互联网 发布:淘宝店办理营业执照 编辑:程序博客网 时间:2024/06/07 10:39

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.

Input

In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

Each game is represented by a pair of scores ab (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

Output

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).

Example
Input
62 475 458 816 16247 9941000000000 1000000
Output
YesYesYesNoNoYes
Note

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。判断最后的分数是否存在

分析:

如果存在,则两人必有一个是一份因子,一份两份因子的乘积,又因为是多组比赛,所以第一个人有输有赢,但有一个显著的特点,就是两个人成绩的乘积一定是某个数的三次方,如果找到这个整数,并且保证每个人的成绩里必有一份,即(a*a%b==0&&b*b%a==0),但是这个代码有个重要的问题就是容易超时,所以只能用C语言,输入输出都要。

代码:

#include<iostream>#include<cstring>#include<queue>#include<cstdio>#include<algorithm>using namespace std;int main(){    int n,i,j,f;    long long int a,b;    cin>>n;    for(i=0;i<n;i++)    {        scanf("%lld %lld",&a,&b);     long long int mid,l,r;     l=1;     r=1000000;    //cout<<"nnnnnnnn"<<n<<endl;    f=0;    while(l<=r)    {        mid=(l+r)/2;        if(mid*mid*mid==a*b){f=1;break;}        else        if(mid*mid*mid<a*b)l=mid+1;        else            r=mid-1;    }        if(a*a%b==0&&b*b%a==0&&f)           printf("YES\n");        else            printf("NO\n");    }}

感想:

这个题我是真的没有想出来某个数的立方,这就是一个难点,还有二分我也没有想到。。。。。总之这个题很难

原创粉丝点击