CodeForces 573 A.Bear and Poker (简单数学)

A.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.

Examples
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.

题意:

给n个数,可以把某个数乘3或者某个数乘2任意次
问是否有可能把所有数变得相同

思路:

假设可以相同,设最后相同的数为K
由题意可知k=2x3yz,(其中xyz为整数)

所以把K不断除以2和3就能得到z

把每个a[i]不断除以2和3得到剩下的数z
判断剩下的数z是否相同就行了

code:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define int long long
const int maxm=1e5+5;
int a[maxm];
int n;
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        while(a[i]%3==0){
            a[i]/=3;
        }
        while(a[i]%2==0){
            a[i]/=2;
        }
    }
    sort(a+1,a+1+n);
    n=unique(a+1,a+1+n)-a-1;
    if(n==1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值