标签:
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?
First line of input contains an integer n (2?≤?n?≤?105), the number of players.
The second line contains n integer numbers a1,?a2,?...,?an (1?≤?ai?≤?109) — the bids of players.
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
4 75 150 75 50
Yes
3 100 150 250
No
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.
任何数都可以表示成 x=2^n*3^n*num, 只要这些数中num都相同,就输出yes.
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int gcd(int a,int b) // 最大公约数模板 { if(a<b) return gcd(b,a); int r; while(b) {r=a%b;a=b;b=r;} return a; } int lcm(int a,int b) {return a/gcd(a,b)*b;} //最小公倍数模板 const int maxn=1e5+100; int a[maxn]; int main() { int n,i,j; int num; cin>>n; cin>>a[1]; num=a[1]; for(i=2;i<=n;i++) { cin>>a[i]; num=gcd(num,a[i]); } while(num%2==0) num/=2; while(num%3==0) num/=3; for(i=1;i<=n;i++) { int tow=1,three=1; while(a[i]%(tow*2)==0) tow*=2; while(a[i]%(three*3)==0) three*=3; if(tow*three*num!=a[i]) { printf("No\n"); return 0; } } printf("Yes\n"); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker(gcd模拟)
标签:
原文地址:http://blog.csdn.net/h1021456873/article/details/48131935