Codeforces Round #318 C - Bear and Poker

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.

这个题目就是说,窝们的主角,limak是个熊老人(old bear--老熊) ,这一天他去了赌场。蓝后这里有N个玩家,每个人有ai块钱。每个人可以让自己的钱翻两倍或者翻三倍任意次, 蓝后问有没有可能每个人的钱都一样。

明白了题意之后 觉得这个题目莫名的眼熟,觉得和cf上以前做过的一个题目差不多。

就是把所有的ai的因子中的2和3 除掉,因为这些因子都是可以通过翻倍翻三倍的得到的;

然后剩下的因子如果有不同,那莫就不可能得到一样的

#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
        
        
using namespace std;
int n,m;
int s[200000];
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i = 1; i <= n; i++)
        {
            scanf("%d",&s[i]);
            while(s[i]%2==0) s[i]/=2;
            while(s[i]%3==0) s[i]/=3;
        }
        int flag = 0;
        for(int i = 1; i < n; i++){
            if(s[i]!=s[i+1])
            {
                flag = 1;
                break;
            }
        }
        if(flag)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}
       
       
      
      
     
     
    
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值