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.
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 6 int gcd(int a,int b) 7 { 8 if(a<b) 9 return gcd(b,a); 10 else if(b==0) 11 return a; 12 else 13 return gcd(b,a%b); 14 } 15 16 int main() 17 { 18 int n; 19 int i,j,k; 20 int a[100005]; 21 scanf("%d",&n); 22 for(i=1;i<=n;i++) 23 { 24 scanf("%d",&a[i]); 25 } 26 int flg=1,x,y,z; 27 for(i=2;i<=n;i++) 28 { 29 z=gcd(a[i-1],a[i]); 30 x=a[i-1]/z,y=a[i]/z; 31 while(x>1) 32 { 33 if(x%2==0) 34 x=x/2; 35 else if(x%3==0) 36 x=x/3; 37 else 38 { 39 flg=0; 40 break; 41 } 42 } 43 while(y>1) 44 { 45 if(y%2==0) 46 y=y/2; 47 else if(y%3==0) 48 y=y/3; 49 else 50 { 51 flg=0; 52 break; 53 } 54 } 55 if(flg==0) 56 break; 57 } 58 if(flg==1) 59 printf("Yes "); 60 else 61 printf("No "); 62 return 0; 63 }