Codeforces Round 833A-The Meaningless Game
来源:互联网 发布:算法的乐趣 epub 编辑:程序博客网 时间:2024/05/22 17:00
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值,赢了的人分数乘以k^2,输了的人分数乘以k。
告诉你两人的最终分数,求游戏可不可能出现这种结果。
根据得分的关系,可以看出两人分数相乘,得到的结果是所有k值的乘积的三次方。
两个人的分数一定是 所有k值乘积的倍数。
根据这个关系就可以判断游戏结果成不成立。
我做的时候在计算k乘积的时候出了点问题= =。
最好是先将两人分数分别开三次方(pow(x,1.0/3))再相乘向上取整得到k的乘积。
#include<iostream>#include<cstring>#include<string>#include<cmath>#include<map>#include<queue>#include<vector>#include<stack>#include<algorithm>#include<stdio.h>#include<cstdio>#define Max 100000using namespace std;map<char,int> mp1,mp2;//¿ªÊ¼¡¢½áÊøvoid f(){ char c='A'; for(; c<='Z'; c++) { mp1[c]=-1; mp2[c]=-1; }}void clr(){ mp1.clear(); mp2.clear();}int main(){ string s; bool flag; int T; int i,j,k,t; int m,n; double x,y; int l; bool flag1,flag2; while(cin>>T) { for(i=0; i<T; i++) { scanf("%d %d",&m,&n); x=pow(m,1.0/3); y=pow(n,1.0/3); l=ceil(x*y); if(m%(int)l==0&&n%(int)l==0) flag=true; else flag=false; if(flag) printf("YES\n"); else printf("NO\n"); } } return 0;}
- Codeforces Round 833A-The Meaningless Game
- Codeforces 833A-The Meaningless Game
- Codeforces Round #426 (Div. 1) A. The Meaningless Game
- CodeForces 833 A.The Meaningless Game(水~)
- codeforces 426 Div2C 833A The Meaningless Game(二分||数学)
- Codeforces Round #426 (Div. 2) C. The Meaningless Game & A, B题代码及错误总结
- Codeforces Round #426 (Div. 2) A B C The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- (Codeforces Round #426 (Div. 2)) C.The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
- Codeforces Round #426 (Div. 2)-C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C The Meaningless Game
- (数学或二分)Codeforces Round #426 C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
- 1025. PAT Ranking (25)
- 【二分+RMQ】玲珑oj 1149
- SVN常用命令
- 筛法快速求解素数
- 用matlab在图像上画矩形框,并保存坐标到文本中
- Codeforces Round 833A-The Meaningless Game
- ios-饼图和柱状图的绘制
- 多线程之初理解
- Linux和Windonws下静态库与动态库(动态库篇)
- HDU3264 Open-air shopping malls【几何】
- Recycleview的各种炫酷应用
- 【转】【Oracle】oracle登录验证的三种方式(详解)
- [Leetcode P10]Regular Expression Matching 正则匹配
- 在linux下安装mysql