Codeforces Round 833A-The Meaningless Game

来源:互联网 发布:算法的乐趣 epub 编辑:程序博客网 时间:2024/05/22 17:00

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 a, b (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
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes

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.

两个人玩游戏,两人分数初始值为1,每一回合选择一个k值,赢了的人分数乘以k^2,输了的人分数乘以k。
告诉你两人的最终分数,求游戏可不可能出现这种结果。
根据得分的关系,可以看出两人分数相乘,得到的结果是所有k值的乘积的三次方。
两个人的分数一定是 所有k值乘积的倍数。
根据这个关系就可以判断游戏结果成不成立。
我做的时候在计算k乘积的时候出了点问题= =。
最好是先将两人分数分别开三次方(pow(x,1.0/3))再相乘向上取整得到k的乘积。

#include<iostream>#include<cstring>#include<string>#include<cmath>#include<map>#include<queue>#include<vector>#include<stack>#include<algorithm>#include<stdio.h>#include<cstdio>#define Max 100000using namespace std;map<char,int> mp1,mp2;//¿ªÊ¼¡¢½áÊøvoid f(){    char c='A';    for(; c<='Z'; c++)    {        mp1[c]=-1;        mp2[c]=-1;    }}void clr(){    mp1.clear();    mp2.clear();}int main(){    string s;    bool flag;    int T;    int i,j,k,t;    int m,n;    double x,y;    int l;    bool flag1,flag2;    while(cin>>T)    {        for(i=0; i<T; i++)        {            scanf("%d %d",&m,&n);               x=pow(m,1.0/3);               y=pow(n,1.0/3);               l=ceil(x*y);                if(m%(int)l==0&&n%(int)l==0)                    flag=true;                else flag=false;                if(flag)                    printf("YES\n");                else printf("NO\n");            }        }    return 0;}
阅读全文
0 0
原创粉丝点击