Codeforces Round #426 (Div. 2) C:The Meaningless Game(思维)
来源:互联网 发布:plc编程功能块 编辑:程序博客网 时间:2024/06/06 00:59
C. The Meaningless Game
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.现在有n个查询,每个查询表示两个人最终的分数,问是否有一种游戏过程,使得这个最终分数是可能出现的。
题解:
首先a*b一定是一个立方数,但是不一定满足,例如2,32.所以a,b一定得能整出这个立方数开三次方。
代码:
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<vector>#include<queue>#include<set>#include<algorithm>#include<map>#include<math.h>using namespace std;typedef long long int ll;typedef pair<int,int>pa;const int N=1e5+10;const int mod=1e9+7;const ll INF=1e18;int read(){ int x=0; char ch = getchar(); while('0'>ch||ch>'9')ch=getchar(); while('0'<=ch&&ch<='9') { x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); } return x;}/***********************************************************/map<ll,int>s;int t;ll a,b;void init(){ for(ll i=1; i<=1000000; i++) { ll tmp=i*i*i; s[tmp]=i; }}int main(){ init(); scanf("%d",&t); while(t--) { scanf("%I64d%I64d",&a,&b); ll c=a*b; if(s[c]>0) { ll tmpp=s[c]; if(a%tmpp==0&&b%tmpp==0)puts("Yes"); else puts("No"); } else puts("No"); }}
- Codeforces Round #426 (Div. 2) C:The Meaningless Game(思维)
- Codeforces Round #426 (Div. 2)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 思维 D. The Bakery dp
- Codeforces Round #426 (Div. 2) C. The Meaningless Game 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 (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 (Div. 2) C:The Meaningless Game The Meaningless Game
- C. The Meaningless Game(Codeforces Round #426 (Div. 2) C)
- Codeforces Round #426 (Div. 2) C. The Meaningless Game(简单数学)
- Codeforces Round #426 (Div. 2)The Meaningless Game【数学题】【水题】
- 好题-Round #426 (Div. 2)C-二分&&思维||质因数分解-The Meaningless Game
- MySQL+DBUtils+C3P0+ Servlet+HTML完成Web端登陆验证案例实现
- 如何阅读caffe源码
- Python Algorithms Learning Notes(1)--Asymptotic Notations
- linux下pip使用可能遇到的问题
- C++多态,虚函数作用及底层实现原理
- Codeforces Round #426 (Div. 2) C:The Meaningless Game(思维)
- UVa12186 Another Crisis
- verilog中defparam的用法
- 欢迎使用CSDN-markdown编辑器
- ios-对图片进行裁剪得到一个新图片和保存到相册
- xynuoj (贪心) 积木大赛 酒馆浪人的博客
- ccnf
- 用栈模拟汉诺塔问题
- Linux学习-例行性工作:单一工作指令at