CodeForces

来源:互联网 发布:淘宝店铺实名认证 编辑:程序博客网 时间:2024/06/15 13:45

C. The Meaningless Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.


题意:有两个人比赛,初始分数都是1,每一轮会有一个分值k,每一轮胜利的人在原先的分数上乘以k^2,输的人在原先的分数上乘以k。现在给你n组分数,比赛是否能出现这样的分数。

思路:设每组两个分数为a,b。a*b一定是某个数的3次方,且这个数一定是a和b的公因数。

学会一个新函数ceil();

函数详解:http://blog.csdn.net/wangjianbing1998/article/details/52091855

#include<stdio.h>#include<math.h>int main(){    int n;    scanf("%d",&n);    while(n--)    {        long long a,b;        scanf("%lld%lld",&a,&b);        long long c=ceil(cbrt(a*b));        if(c*c*c==a*b&&a%c==0&&b%c==0)            printf("YES\n");        else            printf("NO\n");    }}


原创粉丝点击