Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There is N players (including Limak himself) and right now all of them has bids on the table. I-th of them have bid with size ai dollars.
Each player can double he bid any number of times and triple his bid any number of times. The casino have a great jackpot for making all bids equal. Is it possible this Limak and his friends would win a jackpot?
Input
First line of input contains an integer n (2?≤? N? ≤?105), the number of players.
The second line containsNInteger numbers a1,? a 2,?...,? a N (1?≤? a i? ≤?109 )-the bids of players.
Output
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Sample Test (s) input
475 150 75 50
Output
Yes
Input
3100 150 250
Output
No
Note
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 this in the second sample test there is no-to-make all bids equal.
Any number can be represented as x=2^n*3^n*num, as long as NUM is the same in these numbers, the output is yes.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int gcd (int a,int b) //Greatest common divisor template {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 (b) *b;} Least common multiple Template 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;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces Round #318 [Russiancodecup Thanks-round] (Div. 2) C. Bear and Poker (GCD analogue)