CodeForces - 834C The Meaningless Game 思维
2017-07-31 12:04
411 查看
C. The Meaningless Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
![](http://codeforces.com/predownloaded/90/3a/903ab1fdd929cfd0e0b359f5548a09b88e417265.png)
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 histo
4000
ry 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
output
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.
题意:每局游戏胜者*k平方,败者*k,给出最后比分结果,判断是否合法。
题解:一开始想着两个数相除,一转念发现直接相乘的话,就是某数的k的三次方。昨天打到这里wa了五次。最后一分钟才想到比如1 64的情况,应该加一个两个数都能被这个开三次方的数整除,加上这个才是充分条件。第二天补题,莫名被long long卡了精度?
代码:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
![](http://codeforces.com/predownloaded/90/3a/903ab1fdd929cfd0e0b359f5548a09b88e417265.png)
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 histo
4000
ry 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.
题意:每局游戏胜者*k平方,败者*k,给出最后比分结果,判断是否合法。
题解:一开始想着两个数相除,一转念发现直接相乘的话,就是某数的k的三次方。昨天打到这里wa了五次。最后一分钟才想到比如1 64的情况,应该加一个两个数都能被这个开三次方的数整除,加上这个才是充分条件。第二天补题,莫名被long long卡了精度?
代码:
#include<bits/stdc++.h> #define debug cout<<"aaa"<<endl #define mem(a,b) memset(a,b,sizeof(a)) #define LL long long #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define MIN_INT (-2147483647-1) #define MAX_INT 2147483647 #define MAX_LL 9223372036854775807i64 #define MIN_LL (-9223372036854775807i64-1) using namespace std; const int N = 100000 + 5; const int mod = 1000000000 + 7; LL a,b,n; double num; int t; bool flag; int main(){ scanf("%d",&t); while(t--){ scanf("%I64d%I64d",&a,&b); num=a*b; flag=0; n=pow(num,1.0/3); for(LL i=n-1;i<=n+1;i++){ if(i*i*i==a*b&&a%i==0&&b%i==0){//这里a*b换成num就错了,也不知道为什么。根据样例2调了一下才过 flag=1; } } if(flag){ puts("Yes"); } else{ puts("No"); } } return 0; }
相关文章推荐
- Codeforces 582B Once Again...【思维YY+Dp(LIS)】好题~
- CodeForces 732D Exams (思维+set乱搞)
- CodeForces - 814B(思维)
- 【思维】CodeForces - 724B Batch Sort
- Codeforces 807C Success Rate【二分+数学思维】
- Codeforces-895B:XK Segments(思维)
- 【CodeForces - 920F 】SUM and REPLACE 【线段树的区间操作+思维】
- codeforces 580B Arpa and a list of numbers 前缀和+思维+分块 (调和级数)
- codeforces-749【思维】
- CodeForces - 819B Mister B and PR Shifts(线性dp+思维)
- Codeforces 421D Bug in Code(思维)
- codeforces 298 C Parity Game 思维问题
- 【CodeForces】701B - Cells Not Under Attack(思维)
- Codeforces 813C The Tag Game【思维+Dfs】
- Codeforces 507C - Guess Your Way Out! (思维)
- Codeforces 557B Pasha and Tea (思维)
- CodeForces - 618D Hamiltonian Spanning Tree 思维
- Codeforces 818D Multicolored Car【思维+线段树】
- Codeforces - 478C. Table Decorations - 思维、贪心
- Codeforces 660A:Co-prime Array(水题+思维)