Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解

A. Bear and Poker

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/573/problem/A

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 ≤ 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 Input

4
75 150 75 50

Sample Output

Yes

HINT

 

题意

给你n个数,你可以把操作任意一个数,使他翻倍或者翻三倍无数次,问你是否可以让所有数都相同

题解

假设最后变成了K,那么K=2^x+3^y+tmp

所以把所有数都按照2和3分解之后,只要剩下的数都是tmp,那就是yes

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
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 a[maxn];
int check(ll x)
{
    if(x==1)
        return 1;
    if(x==2)
        return 1;
    if(x==3)
        return 1;
    if(x%2==0)
        return check(x/2);
    if(x%3==0)
        return check(x/3);
    return 0;
}
int n;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int main()
{
    n=read();
    for(int i=0;i<n;i++)
        a[i]=read();
    sort(a,a+n);
    ll tmp = a[0];
    for(int i=1;i<n;i++)
    {
        tmp = gcd(tmp,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        if(!check(a[i]/tmp))
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
        cout<<"Yes"<<endl;
}

 

posted @ 2015-08-30 10:45  qscqesze  阅读(416)  评论(0编辑  收藏  举报