CodeForces 833 A.The Meaningless Game(水~)
来源:互联网 发布:电脑版淘宝网站 编辑:程序博客网 时间:2024/06/05 14:13
Description
两个人比赛,初始得分都是1,每轮会随机抽一个自然数k,胜者得分乘k^2,败者得分乘k,现在给出两个人n轮比赛后的得分,问是否存在合法的情况满足这两个得分
Input
第一行一整数n表示比赛轮数,之后n行每行两个正整数a,b表示两个人的得分(1<=n<=350000,1<=a,b<=1e9)
Output
如果存在合法情况则输出Yes,否则输出No
Sample Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Sample Output
Yes
Yes
Yes
No
No
Yes
Solution
问题转化为是否存在k1,k2使得a=k1^2*k2,b=k1*k2^2,先判断a*b是否可以开三次方,如果可以开,设a*b=x^3,如果a,b均可以整除x则Yes,否则No,可以先把所有i^3预处理,每次二分查判x是否存在
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;typedef pair<int,int>P;const int INF=0x3f3f3f3f,maxn=1000001;ll t[maxn];void init(){ for(int i=0;i<=1000000;i++)t[i]=(ll)i*i*i;}int main(){ init(); int n,a,b; scanf("%d",&n); while(n--) { scanf("%d%d",&a,&b); ll c=(ll)a*b; int pos=lower_bound(t,t+maxn,c)-t; //printf("pos=%d\n",pos); if((ll)pos*pos*pos==c&&a%pos==0&&b%pos==0)printf("Yes\n"); else printf("No\n"); } return 0;}
阅读全文
0 0
- CodeForces 833 A.The Meaningless Game(水~)
- Codeforces Round 833A-The Meaningless Game
- Codeforces 833A-The Meaningless Game
- codeforces 426 Div2C 833A The Meaningless Game(二分||数学)
- CodeFroces 833A. The Meaningless Game(数学)
- The Meaningless Game 【codeforces】【思维】
- Codeforces Round #426 (Div. 1) A. The Meaningless Game
- (CodeForces 883A) The Meaningless Game 二分答案思路+骚操作
- Codeforces 834 C The Meaningless Game(二分)
- 【Codeforces】834C. The Meaningless Game
- 【CodeForces】426Div2 C The Meaningless Game
- codeforces 834C (The Meaningless Game)
- CodeForces #426 div2 C The Meaningless Game
- Codeforces 834C The Meaningless Game【思维】
- codeforces 834 C The Meaningless Game
- codeforces The Meaningless Game 数学思维
- codeforces 834 C The Meaningless Game
- CodeForces 834C The Meaningless Game
- 版本控制系统之SVN使用
- 01.JS基础基本特点
- Kotlin Android 实战(一)闪屏页面
- 5. Longest Palindromic Substring
- salesforce中实现点击编辑按钮,在inputField上展示已保存的记录值而非清空值&自定义展示Approval History相关列表
- CodeForces 833 A.The Meaningless Game(水~)
- Python之操作MySQL数据库(二)
- 判断一个序列是否是另外一个序列的子序列的算法
- Cognos学习笔记系列(一)-软件安装
- Java:输入某年某月某日,判断这一天是这一年的第几天?
- 地下挖掘哪家强?机器小“獾”来帮忙
- Andfix源码分析
- Eclipse上如何安装git,及上传本地项目到github
- cocos2d-x lua如何去除多点触摸模式