其他分享
首页 > 其他分享> > The Meaningless Game 题解

The Meaningless Game 题解

作者:互联网

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^2 \]

,输的乘以k,现在给你最终这两个人的得分,让你判断是否有这个可能是这两个分数,有可能的话Yes,否则No。

思路

对于A和B两个人来说,初始为1,我们假设以后每局的k是

\[a_1,a_2......a_n \]

.A和B的分数分别是

\[x_1,x_2. \]

那么到最后

\[x_1*x_2=a_1^3*a_2^3*......a_n^3. \]

显然x_1*x_2开三次方是整数①。

而且最小得分:

\[a_1*a_2*a_3*......a_n. \]

也就是上面求出的三次根号下

\[x_1*x_2. \]

最大得分:

\[a_1^2*a_2^2*a_3^2*......a_n^2. \]

其他得分不论如何都是最小得分的整数倍②。

根据①和②即可判断

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
const int maxn=350000+5;
int n;
long long a,b,c;
int main(){
//	freopen("1.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld%lld",&a,&b);
		c=(pow(a*b,1.0/3)+0.5);
		if(a*b!=c*c*c||a%c||b%c)printf("No\n");
		else printf("Yes\n");
	}
	return 0;
} 

标签:number,题解,game,Meaningless,Game,each,Yes,include,Slastyona
来源: https://www.cnblogs.com/Lour688/p/12751657.html