• Codeforce 573A. Bear and Poker


    Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are nplayers (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.

    将2将3除尽,剩下的数如果一致即可

    #include <cstdio>
    #include <cctype>
    #include <stdlib.h>
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <map>
    using namespace std;
    typedef long long LL;
    int n;
    LL times = 0;
    
    int main() {
      // freopen("test.in","r",stdin);
      cin >> n;
      LL a;
      cin >> a;
      int ok = 1;
      while (a > 1 && a % 2 == 0){
        a = a / 2;
      }
      while (a > 1 && a % 3 == 0){
        a = a / 3;
      }
      times = a;
      for (int i=1;i<n;i++){
        LL b;
        cin >> b;
        if (!ok) continue;
        if (b % times != 0){
          ok = 0; continue;
        }
        else {
          b = b / times;
          while (b > 1 && b % 2 == 0){
            b = b / 2;
          }
          while (b > 1 && b % 3 == 0){
            b = b / 3;
          }
          if (b > 1){
            ok = 0; continue;
          }
        }
      }
      if (ok) cout << "Yes";
      else cout << "No";
      return 0;
    }
    View Code
  • 相关阅读:
    处在什么都想学,却又不知道怎么学的处境
    启动MongoDB shell客户端会什么会一闪而过
    Socket.io发送消息含义
    轮询、长轮询与Web Socket的前端实现
    org.apache.commons.lang3.StringUtils类中isBlank和isEmpty方法的区别
    JS学习笔记10_Ajax
    JS学习笔记9_JSON
    JS学习笔记8_错误处理
    JS学习笔记7_表单脚本
    JS学习笔记6_事件
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6814760.html
Copyright © 2020-2023  润新知