codeforces 834 C The Meaningless Game
2017-07-31 14:32
441 查看
题目:http://codeforces.com/contest/834/problem/C
大致题意:
有n轮比赛,每轮比赛有多个回合,每个回合规定一个自然数k,赢的人分数 * k^2 ,输的人分数 * k 。对于每轮比赛,输入 分数 a和b 判断是否是符合比赛规则的分数。
解法:
对于每轮比赛,如果 a * b == K * K * K ( K = k1 * k2 … km,m个回合k的乘积) ,且 a 和 b 能够同时被K整除 ,说明 分数 a和b 是符合比赛规则的分数 , 否则 就不符合。利用二分查找的方法求K。
代码:
大致题意:
有n轮比赛,每轮比赛有多个回合,每个回合规定一个自然数k,赢的人分数 * k^2 ,输的人分数 * k 。对于每轮比赛,输入 分数 a和b 判断是否是符合比赛规则的分数。
解法:
对于每轮比赛,如果 a * b == K * K * K ( K = k1 * k2 … km,m个回合k的乘积) ,且 a 和 b 能够同时被K整除 ,说明 分数 a和b 是符合比赛规则的分数 , 否则 就不符合。利用二分查找的方法求K。
代码:
#include <iostream> #include <cmath> #include <cstdio> using namespace std; const int N = 1e6; long long nRoot[N+10]; long long root(long long num){ int sInd = 0 , eInd = N; int midInd; while(sInd <= eInd){ midInd = (sInd + eInd)/2; if(nRoot[midInd] == num) return midInd; else if(nRoot[midInd] < num) sInd = midInd + 1; else eInd = midInd - 1; } return eInd; } int main(){ int n; cin >> n; long long a,b; for(long long i = 0; i <= N ; i++){ nRoot[i] = i*i*i; } for(int i = 0 ; i < n ; i++){ scanf("%lld%lld",&a,&b); long long sum = a * b; long long k3 = root(sum); if( k3*k3*k3 == sum && (a%k3==0) && (b%k3==0) ) printf("Yes\n"); else printf("No\n"); } }
相关文章推荐
- codeforces 834 C The Meaningless Game
- Codeforces 834(426 Div.2) C.The Meaningless Game
- Codeforces 834 C The Meaningless Game(二分)
- CodeForces 834 C. The Meaningless Game
- The Meaningless Game 【codeforces】【思维】
- (CodeForces 883A) The Meaningless Game 纯正的数学思维题(有点卡cin时间)
- CodeForces 833 A.The Meaningless Game(水~)
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
- CodeForces - 834C. The Meaningless Game
- Codeforces - 834C. The Meaningless Game - 数学
- 【CodeForces】426Div2 C The Meaningless Game
- Codeforces 833A-The Meaningless Game
- CodeForces - 834C The Meaningless Game
- (CodeForces 883A) The Meaningless Game 二分答案思路+骚操作
- codeforces 834C (The Meaningless Game)
- codeforces 549C C. The Game Of Parity(博弈)
- 【Codeforces Round #426 (Div. 2) C】The Meaningless Game
- Codeforces Round #426 (Div. 2)-C. The Meaningless Game
- 【思维】833A - The Meaningless Game
- Codeforces Round #426 (Div. 2) B.The Festive Evening+C.The Meaningless Game