首页 技术 正文
技术 2022年11月7日
0 收藏 987 点赞 937 浏览 2024 个字

题目描述

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

样例

样例输入


样例输出

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.

分析

一句话题意:现在两个人做游戏,每个人刚开始都是数字1,谁赢了就能乘以k^2,输的乘以k,现在给你最终这两个人的得分,让你判断是否有这个可能,有可能的话Yes,否则No。

我们假设游戏进行了 i 轮,每次选择的数分别是n1、n2、n3……ni

那么第一次,必定有一个人乘n12,另一个人乘n1,同样地,第二次,必定有一个人乘n22,另一个人乘n2

我们设A为第一个人最终的得分,B为第二个人最终的得分,那么很显然,如果结果正确的话,必定有A*B=n13*n23*n33*……*ni3

所以我们要判断对A*B开三次根号后的数是不是整数

同时,一个人的最小得分必定为n1*n2*n3*……*ni,最大得分必定为n12*n22*n32*……*ni2

所以我们还要判断A和B能否被它们的乘积开三次根号的结果整除

如果上述条件都满足,就输出Yes,否则输出No

代码

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
int main(){
ll t;
scanf("%lld",&t);
while(t--){
ll a,b;
scanf("%lld%lld",&a,&b);
ll tot=a*b;
ll js=round(pow(1.0*tot,1.0/));
//对A*B开三次根号取整
if(js*js*js==tot && a%js== && b%js==) printf("Yes\n");
else printf("No\n");
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894