CodeForces 834 C. The Meaningless Game

来源:互联网 发布:80端口攻击 编辑:程序博客网 时间:2024/06/10 14:10

原题连接:http://codeforces.com/problemset/problem/834/C

题意:

有一个游戏,进行多轮,一开始每个人都有1分。

然后游戏选择一个数字K,如果有一方先说出数字K,那么他的分数会乘以K²。

经过多轮游戏后,A,B的分数分别是a分,b分。

请问a,b是否符合游戏规则,是则输出YES,不是则输出NO。


题解:

a * b 一定是某个数的三次方,且a % k == 0 b % k == 0,只要找到这个数字进行判断即可。

数据太大,每次枚举一定超时,用二分。


#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<queue>#define ll long longusing namespace std;const int MAX = 1e5 + 5;const ll INF = 1e10;const int MOD = 1e9 + 7;int main(){int n;scanf("%d",&n);while(n--){ll x,y;scanf("%lld %lld",&x,&y);ll l = 1,r = 1e6,m;ll ans = -1;while(l <= r){m = (l + r) >> 1;ll tri = m * m * m;if(tri <= x * y){if(tri == x * y)ans = m;l = m + 1;}else{r = m - 1;}}if(ans == -1 || x % ans || y % ans)puts("No");elseputs("Yes");}return 0;}