Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker

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

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.

题意:给你n个数,每个数可以乘2或3,问你是否能让所有数相同;

题解:先找出最大公约数,再不断除2,3,判断是否是1就好了

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef __int64 ll;
#define inf 0x7fffffff
using namespace std;
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
//**************************************************************************************

ll  gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
int A[100005];
int main()
{
    int n=read();
    ll a=read();
    int cnt=0;
    A[++cnt]=a;
    for(int i=1;i<n;i++)
    {
       int  b=read();
       A[++cnt]=b;
       a=gcd(a,b);
    }
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        A[i]/=a;
        while(A[i]%2==0)A[i]=A[i]/2;
        while(A[i]%3==0)A[i]=A[i]/3;
        if(A[i]!=1){
            flag=1;
            cout<<"NO"<<endl;
            break;
        }
    }
    if(!flag)cout<<"YES"<<endl;
    return 0;
}
代码

 

转载于:https://www.cnblogs.com/zxhl/p/4770406.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值