CF #318 C. Bear and Poker

C. Bear and Poker
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ≤ 105), the number of players.

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 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
4
75 150 75 50
output
Yes
input
3
100 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 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\n");
60     else
61         printf("No\n");
62     return 0;
63 }
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4770802.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值