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. Shell产出01|定时清日志脚本|Shell

    需求:每天定时清理空间占有率为x%的文件系统,包括PAMS和PMTS #!/bin/bash : <<EOF @Time:2023/03/22 @Author:Chase 版本:定时任务实 ...

  2. 拉普拉斯金字塔在多图HDR算法中的应用以及多曝光图像的融合算法简介。

    在SSE图像算法优化系列二十九:基础的拉普拉斯金字塔融合用于改善图像增强中易出现的过增强问题(一) 一文中我们曾经描述过基于几种高频融合法则的拉普拉斯金字塔融合算法,那里是主要针对2副图像的.实际的应 ...

  3. 「hackerrank - 101hack43」K-Inversion Permutations

    link. 原问题即:请你给出不同的序列 \(\{a_n\}\) 的数量,满足 \(0\leqslant a_i<i\),且 \(\sum a_i=k\). 那么写出 \({a_n}\) 的 o ...

  4. CAS中ABA问题的解决

    转自(here)   CAS问题的产生 在运用CAS做Lock-Free操作中有一个经典的ABA问题: 线程1准备用CAS将变量的值由A替换为B,在此之前,线程2将变量的值由A替换为C,又由C替换为A ...

  5. Oracle问题:ORA-01109解决办法

    出现问题: 在数据库服务器端,查询dual表,报ORA-01109错误 ORA-01109:database not open 查看: sqlplus / as sysdba;--管理员登录 sele ...

  6. 【最佳实践】MongoDB导入数据时重建索引

    MongoDB一个广为诟病的问题是,大量数据resotore时索引重建非常缓慢,实测5000万的集合如果有3个以上的索引需要恢复,几乎没法成功,而且resotore时如果选择创建索引也会存在索引不生效 ...

  7. MySQL的sql_mode设置导致报错1292

    在MySQL8.0的一个PXC集群中,默认的sql_mode设置如下: select @@sql_mode; +-------------------------------------------- ...

  8. [NSSCTF 2022 Spring Recruit]ezgame

    打开题目,发现是一个网页小游戏,就开始F12 提示到,需要分数超过65,才会得到flag 但不可能用手点吧(不怕麻烦还是可以) flag肯定是藏在了某个地方,仔细找找 发现有一个css,js文件,依次 ...

  9. 区间检测(range)

    区间检测(range) 时间限制: 1 Sec  内存限制: 128 MB 题目描述 给定一个长度为n的序列,进行m次检测,每次检测某个区间中,是否有重复的数. 输入 第一行,两个整数n和m,表示序列 ...

  10. CF1401C

    题目简化和分析: 交换数组使其变为升序,满足交互的两数 \(a_i\) 与 \(a_j\),$ \min{a_i(1\le i\le n)}|\gcd(a_i,a_j)$ . 简单思维题,Div.2 ...