CodeForces 834C The Meaningless Game
来源:互联网 发布:淘宝卖家中心登录网 编辑:程序博客网 时间:2024/06/10 14:20
题目链接:http://codeforces.com/contest/834/problem/C
题意:一个人和他的一只狗一起玩游戏,游戏n局,游戏规则如下,每轮两人选择一个数字k,先喊出来的那个就在原有的积分乘上k^2,另一个则乘上k,最后,那个人忘了游戏谁赢了,只是记得每局的两人最后得分,但又不确定这个得分是否正确,让你来判断,这些给出的得分是否合法
解析:首先一个乘k^2,一个乘k,那么gcd的结果肯定有k,而有一个数剩下的也一定是k,进行若干轮后的结果去gcd的话,应该是几轮的k的连乘,而两个最终得分除以gcd的结果后相乘应该等于gcd,但是有一种情况就是,同一个k玩了两局,然后两局赢的人都不一样,就比如8 8,就是两局都是2,但是这样的gcd也有一个规律,那就是一定能开三次方,所以就用上述那些来进行判断,判能否开三次方由于pow的精度问题,我选择了用二分,但是二分要注意下longlong的时候
#include <bits/stdc++.h>using namespace std;int main(void){ int n; scanf("%d",&n); for(int i=0;i<n;i++) { int a,b; scanf("%d %d",&a,&b); int tmp = __gcd(a,b); int t1 = a/tmp; int t2 = b/tmp; if(tmp%(t1*t2)==0) { int t3 = tmp/(t1*t2); int l = 1,r = t3,flag = 0; for(int k=0;k<200;k++) { int mid = (l+r)/2; long long tt = 1LL*mid*mid; if(tt>t3 || tt>1e10) { r = mid; continue; } tt *= mid; if(tt==t3) { flag = 1; break; } if(tt<t3) l = mid; else r = mid; } if(flag) puts("YES"); else puts("NO"); } else puts("NO"); } return 0;}
阅读全文
0 0
- 【Codeforces】834C. The Meaningless Game
- codeforces 834C (The Meaningless Game)
- Codeforces 834C The Meaningless Game【思维】
- codeforces 834 C The Meaningless Game
- codeforces 834 C The Meaningless Game
- CodeForces 834C The Meaningless Game
- CodeForces 834 C. The Meaningless Game
- Codeforces 834(426 Div.2) C.The Meaningless Game
- Codeforces 834 C The Meaningless Game(二分)
- 【CodeForces】426Div2 C The Meaningless Game
- CodeForces #426 div2 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
- The Meaningless Game 【codeforces】【思维】
- (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
- 我使用过的框架的基本涵盖所有版本CDN网址
- 最小生成树 堆优化的Prim算法
- jsp 基础语法
- throw和throws的区别
- 各个JAVA场景下的内存图
- CodeForces 834C The Meaningless Game
- 欢迎使用CSDN-markdown编辑器
- QT-程序图标设置
- Oil Deposits ——DFS&&BFS
- 13改变HTML样式
- 解决react vr加载js模型失败的问题
- java ajax实现异步同步请求全面详解
- Android之ViewPager+Fragment实现懒加载
- c++实现工厂方法模式对八大排序的统一管理