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

解题思路:如果a*b==i^3 && a*a%b==0 && b*b%a==0

那么就输出Yes。否则输出No。

ps:这题其实直接用pow就可以解出了,注意精度,但是在处理高精度的方面我比较方。。。所以用二分查找。

也tle几次,发现竟然是习惯性的多查找几个数就超时了。改了之后AC了,但是时间是998ms。。。看了别人的代码都差不多,不造为什么,算了,下次还是用高精度吧。

AC代码:

 1 #include<iostream>
2 #include<stdio.h>
3 using namespace std;
4 int main()
5 {
6 int T;
7 cin>>T;
8 while(T--){
9 long long a,b;
10 scanf("%lld%lld",&a,&b);
11 long long m=a*b;
12 long long l=1,r=1000000,mid=(l+r)/2;
13 bool flag=false;
14 if(a*a%b==0&&b*b%a==0){
15 while(l<=r){
16 mid=(l+r)/2;
17 if((mid*mid*mid)==m){
18 flag=true;
19 break;
20 }
21 else if((mid*mid*mid)>m){
22 r=mid-1;
23 }else{
24 l=mid+1;
25 }
26 }
27 }
28 if(flag) cout<<"Yes"<<endl;
29 else cout<<"No"<<endl;
30 }
31 return 0;
32 }

Codeforces Round #426 (Div. 2) problem C的更多相关文章

  1. CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)

    /* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...

  2. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  3. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  4. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  5. Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation

    还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门  Problem - D - Codeforces 题意 n个数字,n ...

  6. Codeforces Round #426 (Div. 2)

    http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...

  7. Codeforces Round #426 (Div. 2) A,B,C

    A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...

  8. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  9. Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学

    — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...

  10. Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

    Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...

随机推荐

  1. MySQL 使用Navicat delete/insert into/update 大量数据表锁死,kill的线程后线程处于killed状态问题解决

    MySQL 使用delete/insert into/update 大量数据表锁死,kill的线程后线程处于killed状态问题解决 实际生产环境问题描述: 使用Navicat备份BigData数据表 ...

  2. WPF使用Blazor的快速案例

    下面我们将讲解在WPF中使用Blazor,并且使用Blazor做一些文件编辑操作,下面是需要用到的东西 WPF Blazor Masa Blazor Monaco 安装Masa Blazor模板 使用 ...

  3. 使用API调用获取商品数据的完整方案

    ​ 在电子商务应用程序中,商品详情接口是不可或缺的一部分.它用于从电商平台或自己的数据库中获取商品数据,并将其提供给应用程序的其他部分使用.本文将详细介绍如何设计一个完整的商品详情接口方案,其中包括使 ...

  4. Oracle中的having()函数

    having函数用在group by子句的后面,对分组结果集进行条件筛选. 1.having子句包含聚合函数 /*列出平均工资在1000之上,并且最低工资不低于800的工作信息*/select job ...

  5. 使用Blazor WASM实现可取消的多文件带校验并发分片上传

    前言 上传大文件时,原始HTTP文件上传功能可能会影响使用体验,此时使用分片上传功能可以有效避免原始上传的弊端.由于分片上传不是HTTP标准的一部分,所以只能自行开发相互配合的服务端和客户端.文件分片 ...

  6. MySQL系列之MHA高可用——主从复制架构演变介绍、高可用MHA、管理员在高可用架构维护的职责

    文章目录 1. 主从复制架构演变介绍 1.1 基本结构 1.2 高级应用架构演变 1.2.1 高性能架构 1.2.2 高可用架构 2. 高可用MHA ***** 2.1 架构工作原理 2.2 架构介绍 ...

  7. WebKit Insie: Active 样式表

    WebKit Inside: CSS 样式表的匹配时机介绍了当 HTML 页面有不同 CSS 样式表引入时,CSS 样式表开始匹配的时机.后续文章继续介绍 CSS 样式表的匹配过程,但是在匹配之前,首 ...

  8. buu pwn wp(持续更新)

    1.warmup_csaw_2016 main函数如下 __int64 __fastcall main(int a1, char **a2, char **a3) { char s[64]; // [ ...

  9. 【PHP正则表达式】

    [PHP正则表达式] 最近写题总是遇到php正则表达式的匹配函数,于是进行一个总结. 1.什么是正则表达式 是php在进行搜索时用于匹配的模式字符串.一般用于php对特定字符序列的替换和搜索. 2.正 ...

  10. Chromium 消息循环和线程池详解

    Chromium 中的多线程机制由 base 库提供,要理解 Chromium 中的多线程机制,首先要理解的概念就是 base::MessageLoop 和 base::TaskScheduler , ...