codeforces574C数论

Description

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

The second line contains n integer numbers a1, a2, …, an (1 ≤ ai ≤ 10^9) — the bids of players.

Output

Print “Yes” (without the quotes) if players can make their bids become equal, or “No” otherwise.

Sample Input
Input

4
75 150 75 50

Output

Yes

Input

3
100 150 250

Output

No

Hint

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.

题意:最开始每个人都有一个值,任何一个人都可以将自己的值变大两倍或3背,问能不能让所有人的值都相等。
解法:人选两个人出来,a1,a2,按题意方法要有 a12n13m1==a22n23m2==lcm 所以直接判断a1,a2能不能不断的乘2,3得到两个数的最小公倍数就好了。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL a[100005];
int n;
bool judge(){
    for(int i=2;i<=n;i++){
        LL bei=a[i-1]*a[i]/__gcd(a[i-1],a[i]);
        LL F=bei/a[i-1],S=bei/a[i];
        while(F%2==0) F/=2;
        while(F%3==0) F/=3;
        while(S%2==0) S/=2;
        while(S%3==0) S/=3;
        if(F!=1||S!=1) return false;
    }
    return true;
}
int main(){
    while(cin>>n){
        for(int i=1;i<=n;i++) cin>>a[i];
        if(judge()==true) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值