好题-Round #426 (Div. 2)C-二分&&思维||质因数分解-The Meaningless Game
来源:互联网 发布:语文名师讲课软件 编辑:程序博客网 时间:2024/06/06 16:11
http://codeforces.com/contest/834/problem/C
小明和 小华 在玩游戏。。开始值一样,然后指定一个值,他俩开始瞎猜这个值,谁先喊赢了谁就赢(完全随机),赢得人分数 乘以k^2,输的人分数乘以 k,
给你两个值,为是否可能是比赛的分数。
发现规律之后,二分或者直接求都是极好的
还有大佬用质因数分解,类似模拟这个过程。但是过程不太懂,仍在学习中
1 讲解在代码里。
#include <bits/stdc++.h>using namespace std;const int maxn=2008;typedef long long ll;/* 前两种方法差不多,就是发现了规律。 设第一次是 x1 x2 x3 x4 则 甲假定是 x1*x1+ x2*x2+x3+x4; 乙 假定是 x1+x2+x3*x3+x4*x4 我们发现 把两者乘起来 求一下是否为 自然数的3次方就行。 如果是的话,那个k一定是 x1*x2*x3*x4 自然数存在,那四个数一定也存在(打不了一样被, 如果有不一样限制的话可以分解一下因子)、*/int main(){ ll a; ll b; int t; scanf("%d",&t); while(t--){ scanf("%lld%lld",&a,&b); ll r=2*1e6; ll l=0; // cout<<a*b<<endl; bool flag=false; while(l<=r){ ll mid=(l+r)/2; if(1ll*mid*mid*mid==a*b){ flag=true;break; } else if(1ll*mid*mid*mid>a*b) {r=mid-1;} else if(1ll*mid*mid*mid<a*b) {l=mid+1;} } if(a*a%b==0&&b*b%a==0&&flag) puts("YES"); else puts("NO"); } return 0;}
#include <bits/stdc++.h>using namespace std;typedef long long ll;int main(){ int t; ll a,b; scanf("%d",&t); while(t--){ scanf("%lld%lld",&a,&b); ll m=1ll*cbrt(a*b); //ll m=1ll*round(pow(double(a*b),1.0/3)); ll x=a/m;//得到 x1*x2 ll y=b/m; if(x*x*y==a&&y*y*x==b) puts("YES"); else puts("NO"); } return 0;}
#include <bits/stdc++.h>// 这个还没怎么看懂。。。。using namespace std;int not_prime[4234560];vector<int > pp;long long sq[4234560];int prime(){ for (int i=2;i<1000000;i++){ if (!not_prime[i]){ pp.push_back(i); if (1LL*i*i<=1000000) for (int j=i+i;j<=1000000;j+=i){ not_prime[j]=1;//求素数的筛 } } }}int main(){ int n; int a,b; for (int i=1;i<=1000000;i++){ sq[i]=1LL*i*i*i; } prime(); scanf("%d",&n); for (int i=0;i<n;i++){ scanf("%d%d",&a,&b); long long tmp=1LL*a*b; int sz=lower_bound(sq,sq+1000000+1,tmp)-sq; if (sq[sz]==tmp){ int flag=1; for (int j=0;j<pp.size()&&a!=1&&b!=1;j++){ int t1=0,t2=0; while (a%pp[j]==0)t1++,a/=pp[j]; while (b%pp[j]==0)t2++,b/=pp[j]; if (t1<t2)swap(t1,t2); int tim=t1-t2;//???? if (t1<(tim<<1)||t2<tim){ flag=0; break; } t1-=(tim<<1); if (t1%3){ flag=0; break; } } if (a!=1||b!=1||flag==0) puts("No"); else puts("Yes"); } else puts("No"); } return 0;}
阅读全文
0 0
- 好题-Round #426 (Div. 2)C-二分&&思维||质因数分解-The Meaningless Game
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- Codeforces Round #426 (Div. 2)The Meaningless Game(思维+二分)
- Codeforces Round #426 (Div. 2) C. The Meaningless Game 思维 D. The Bakery dp
- Codeforces Round #426 (Div. 2) 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
- (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
- 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 & A, B题代码及错误总结
- (数学或二分)Codeforces Round #426 C. The Meaningless Game
- Codeforces Round #426 (Div. 2) B.The Festive Evening+C.The Meaningless Game
- appium环境搭建
- SOA架构
- Codeforces 330D Biridian Forest【思维+Bfs】
- 并行-Guarded Suspension模式
- linux应用项目(一)数码相框(3)数码相框之电子书
- 好题-Round #426 (Div. 2)C-二分&&思维||质因数分解-The Meaningless Game
- 62. Unique Paths 自己写的一次ac
- PHP——底层运行机制与原理
- Retrofit2 简单的使用
- mybatis整合springmvc遇到的问题(待解决)
- Fork/Join框架介绍
- matlab 写文件去掉科学计数法
- 利用redis的表达式实现速率请求控制器
- 链表复习题