codeforces574C数论
来源:互联网 发布:dnf防卡优化补丁2017 编辑:程序博客网 时间:2024/06/18 01:15
Description
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input
First line of input contains an integer n (2 ≤ n ≤ 10^5), the number of players.
The second line contains n integer numbers a1, a2, …, an (1 ≤ ai ≤ 10^9) — the bids of players.
Output
Print “Yes” (without the quotes) if players can make their bids become equal, or “No” otherwise.
Sample Input
Input
4
75 150 75 50
Output
Yes
Input
3
100 150 250
Output
No
Hint
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal.
题意:最开始每个人都有一个值,任何一个人都可以将自己的值变大两倍或3背,问能不能让所有人的值都相等。
解法:人选两个人出来,a1,a2,按题意方法要有
#include<bits/stdc++.h>using namespace std;#define LL long longLL a[100005];int n;bool judge(){ for(int i=2;i<=n;i++){ LL bei=a[i-1]*a[i]/__gcd(a[i-1],a[i]); LL F=bei/a[i-1],S=bei/a[i]; while(F%2==0) F/=2; while(F%3==0) F/=3; while(S%2==0) S/=2; while(S%3==0) S/=3; if(F!=1||S!=1) return false; } return true;}int main(){ while(cin>>n){ for(int i=1;i<=n;i++) cin>>a[i]; if(judge()==true) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0;}
- codeforces574C数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论
- 数论 ?
- 数论
- 数论
- 数论
- 数论
- 数论
- BZOJ 1864
- Boyer-Moore算法-JAVA实现
- 微信 js-sdk 界面操作接口使用
- SICP 2.04-2.06
- Report Studio 过滤
- codeforces574C数论
- Apache与Tomcat联系及区别
- Java并发(1) i++的线程安全问题
- THINKPHP 使用分页
- vueJs ajax
- 百度地图SDK v3.6.0以上版本setOnMarkerClickListener 失效的问题解决
- 珠海鼎芯imx6 开发板 Qt 移植
- GLIBC_2.14 兼容问题 version `GLIBC_2.14′ not found
- iOS 中webView的使用