Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game
来源:互联网 发布:陈田拆车件有淘宝店吗 编辑:程序博客网 时间:2024/06/07 11:25
题目: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).
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 a, b (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).
题目大意:现在有两个人玩游戏,一开始两个人的分数都是1,每一轮游戏两个人会共同挑选一个数k,游戏获得胜利的选手将自己的分数 *k^2,输了的选手将自己的分数*k.现在有n个查询,每个查询表示两个人最终的分数,问是否有一种游戏过程,使得这个最终分数是可能出现的。
思路:
观察可发现如下特征:
1.a*b=(k1k2k3...kn)^3。
2.(k1k2k3...kn)能整除a,b。
证明:
代码:#include <stdio.h>#include <stdlib.h>#include <iostream>long long a,b;int n;int main(){int i; scanf("%d",&n); while(n--) {scanf("%lld%lld",&a,&b); long long p=a*b,c; c=(long long)round(pow((double)p,(1.0)/(3.0))); if(c==0||(c*c*c)!=p)printf("No\n"); else if(a%c==0&&b%c==0)printf("Yes\n"); else printf("No\n"); } return 0;}
- 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)) 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)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 834(426 Div.2) C.The Meaningless Game
- Codeforces Round #426 (Div. 2) C. The Meaningless Game 思维 D. The Bakery dp
- Codeforces Round #426 (Div. 2) B.The Festive Evening+C.The Meaningless Game
- C. The Meaningless Game(Codeforces Round #426 (Div. 2) C)
- Codeforces Round #426 (Div. 1) A. The Meaningless Game
- 08020001
- 基于DRBD实现MySQL高可用
- 帆起航,再踏征程(一)
- Linux 基础入门-教程文档
- Linux--标准输入输出、重定向及管道运用
- Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game
- ubuntu 16.04 安装pycharm ----通过deb包的方式
- 可持久化。
- 年轻人做好投资
- [SMOJ2073]Bug
- uva-122 树的层次遍历
- web前端学习日记10
- Activity的生命周期
- 方法重写,抽象方法必须重写,抽象类。super.父类里面的方法调用方法。