zoukankan      html  css  js  c++  java
  • CF #318 C. Bear and Poker

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

    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.

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 int gcd(int a,int b) 
     7 { 
     8     if(a<b) 
     9         return gcd(b,a); 
    10     else if(b==0) 
    11         return a; 
    12     else
    13         return gcd(b,a%b); 
    14 } 
    15 
    16 int main()
    17 {
    18     int n;
    19     int i,j,k;
    20     int a[100005];
    21     scanf("%d",&n);
    22     for(i=1;i<=n;i++)
    23     {
    24         scanf("%d",&a[i]);
    25     }
    26     int flg=1,x,y,z;
    27     for(i=2;i<=n;i++)
    28     {
    29         z=gcd(a[i-1],a[i]);
    30         x=a[i-1]/z,y=a[i]/z;
    31         while(x>1)
    32         {
    33             if(x%2==0)
    34                 x=x/2;
    35             else if(x%3==0)
    36                 x=x/3;
    37             else
    38             {
    39                 flg=0;
    40                 break;
    41             }
    42         }
    43         while(y>1)
    44         {
    45             if(y%2==0)
    46                 y=y/2;
    47             else if(y%3==0)
    48                 y=y/3;
    49             else
    50             {
    51                 flg=0;
    52                 break;
    53             }
    54         }
    55         if(flg==0)
    56             break;
    57     }
    58     if(flg==1)
    59         printf("Yes
    ");
    60     else
    61         printf("No
    ");
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    Go语言基础之字符串遍历
    Go语言基础之range
    Go语言的for循环
    Go语言基础之反射
    Go语言基础之接口
    Linux编程简介
    如何使用gcc编译器
    ADS的使用
    bvp4c--语法
    어느 도시 보유 하 면 사랑 이다(事態が発生すれば、ある都市の恋はしません)【Si les villes un amour】{If have love in a city}
  • 原文地址:https://www.cnblogs.com/cyd308/p/4770802.html
Copyright © 2011-2022 走看看