• 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;
    }
    代码
  • 相关阅读:
    1.7 Matrix Zero
    1.6 Image Rotation
    Snake Sequence
    安装 Docker
    开源蓝牙协议栈 BTstack学习笔记
    无法从 repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds 获取文件
    KEIL生成预编译文件
    Duff's device
    Pyinstaller : unable to find Qt5Core.dll on PATH
    HCI 获取蓝牙厂商信息
  • 原文地址:https://www.cnblogs.com/zxhl/p/4770406.html
Copyright © 2020-2023  润新知