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=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//************************************************************************************** ll gcd(ll a,ll b)
{
if(b==)return a;
else return gcd(b,a%b);
}
int A[];
int main()
{
int n=read();
ll a=read();
int cnt=;
A[++cnt]=a;
for(int i=;i<n;i++)
{
int b=read();
A[++cnt]=b;
a=gcd(a,b);
}
int flag=;
for(int i=;i<=n;i++)
{
A[i]/=a;
while(A[i]%==)A[i]=A[i]/;
while(A[i]%==)A[i]=A[i]/;
if(A[i]!=){
flag=;
cout<<"NO"<<endl;
break;
}
}
if(!flag)cout<<"YES"<<endl;
return ;
}

代码

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker的更多相关文章

  1. 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/pro ...

  2. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题

    B. Bear and Blocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pr ...

  3. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) C. Bear and Drawing

    题目链接:http://codeforces.com/contest/573/problem/C题目大意:在两行无限长的点列上面画n个点以及n-1条边使得构成一棵树,并且要求边都在同一平面上且除了节点 ...

  4. 校内选拔I题题解 构造题 Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) ——D

    http://codeforces.com/contest/574/problem/D Bear and Blocks time limit per test 1 second memory limi ...

  5. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列

                                                    A. Bear and Elections                               ...

  6. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers 枚举

                                          B. Bear and Three Musketeers                                   ...

  7. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)

    以后每做完一场CF,解题报告都写在一起吧   暴力||二分 A - Bear and Elections 题意:有n个候选人,第一个候选人可以贿赂其他人拿到他们的票,问最少要贿赂多少张票第一个人才能赢 ...

  8. Codeforces Round #318 (Div. 2) C Bear and Poker (数学)

    简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...

  9. Codeforces Round #539&#542&#543&#545 (Div. 1) 简要题解

    Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...

随机推荐

  1. svn代码回滚命令

    代码回滚提交: 比如要把73回滚到68 svn merge -r 73:68 http://my.repository.com/my/project/trunk 然后commit就行了 svn com ...

  2. Cannot find class [org.apache.commons.dbcp.BasicDataSource]

    错误:Cannot find class [org.apache.commons.dbcp.BasicDataSource] 原因:缺少commons-dbcp.jar

  3. c# 重写索引

    //using System;//using System.Collections.Generic;//using System.Text; //namespace 索引//{//    class ...

  4. C#面向对象面试题集锦

    1.简述C#中的虚方法 答:注意:当使用virtual关键字修饰符后,不允许再同时使用abstract,static,或override关键字进行修饰 使用virtual关键字修饰的方法就是虚方法,虚 ...

  5. 图论&数据结构——并查集

    Wikioi 4246 NOIP模拟赛Day2T1 奶牛的身高  题目描述 Description 奶牛们在FJ的养育下茁壮成长.这天,FJ给了奶牛Bessie一个任务,去看看每个奶牛场中若干只奶牛的 ...

  6. 在Android的webview中定做js的alert,confirm和prompt对话框的方法

    在Android的webview中定制js的alert,confirm和prompt对话框的方法 http://618119.com/archives/2010/12/20/199.html 1.首先 ...

  7. Linux大神必备-文本编辑器

    导读 我们在 Linux 上不缺乏非常现代化的编辑软件,但是它们都是基于 GUI(图形界面)的编辑软件.正如你所了解的:Linux 真正的魅力在于命令行,当你正在用命令行工作时,你就需要一个可以在控制 ...

  8. 他们在军训,我在搞 OI(一)

    Day 1 理论上,我现在不应该坐在电脑前打字,因为早在今天上午 6:20 全体新高一同学就坐车前往军(无)训(尽)基(炼)地(狱)了,而今天上午 6:20 我还在被窝里呢…… 没错,我旷掉了军训,然 ...

  9. Firefox渗透测试黑客插件集

    前天看S哥用Firefox的hackbar进行手动注入进行渗透,觉得直接运用浏览器的插件进行渗透测试有很多优点,既可以直接在前端进行注入等操作,也可以省却了寻找各种工具的麻烦.前端还是最直接的!于是这 ...

  10. 查看daemon使用技巧

    una ~ # ps -ef|egrep "*d$"或"[a-z]d"               //查看现有的服务器上都有哪些服务器进程.root 3509 ...