Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker
2 seconds
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?
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.
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
4
75 150 75 50
Yes
3
100 150 250
No
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) C. Bear and Drawing
题目链接:http://codeforces.com/contest/573/problem/C题目大意:在两行无限长的点列上面画n个点以及n-1条边使得构成一棵树,并且要求边都在同一平面上且除了节点 ...
- 校内选拔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 ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列
A. Bear and Elections ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers 枚举
B. Bear and Three Musketeers ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)
以后每做完一场CF,解题报告都写在一起吧 暴力||二分 A - Bear and Elections 题意:有n个候选人,第一个候选人可以贿赂其他人拿到他们的票,问最少要贿赂多少张票第一个人才能赢 ...
- Codeforces Round #318 (Div. 2) C Bear and Poker (数学)
简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...
- Codeforces Round #539Ȟȟȡ (Div. 1) 简要题解
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...
随机推荐
- Struts2几种传值
1.url向action传值 url为 http://localhost/txyl/teacher_info?method:teacher_info&teacher_seq=dedafdsf3 ...
- 看了让人笑了很多很多次的NB的痔疮经历
前言 这篇杂记其实是去年也就是 2013年9月30日转载的,后来在整理博客分类时七弄八弄误删掉了好多文章,就包括这一篇.今天,2014年9月29日,恰好恰好一年的时候居然在好久未登陆的 OneNote ...
- (8)UI(控件)
1.按钮: 按钮是游戏中最常用的控件类型之一,控制用户点击事件的开关,有正常.按下.禁用三种状态,您可以为他们设置样式及文本. 使用场景 按钮的使用十分普遍,以官方示例中的主场景示例为例, ...
- [Effective JavaScript 笔记]第40条:避免继承标准类
ECMAScript标准库里配备了许多重要的类,如Array,function,以及Date等.扩展这些类生成子类可以方便完成很多工作,但它们的定义具有很多特殊的行为,所以很难写出行为正确的类. Ar ...
- unity StreamingAssets路径
原地址:http://blog.csdn.net/nateyang/article/details/8493791 我们在读写例如XML和TXT文件的时候,在电脑上和手机上路径不一致,造成了很多麻烦, ...
- CUDA 6.5 && VS2013 && Win7:创建CUDA项目
运行环境: Win7+VS2013+CUDA6.5 1.创建win32空项目 2.右键项目解决方案-->生成项目依赖项-->生成自定义 3.右键项目解决方案-->属性-->配置 ...
- HDOJ 1869
#include<stdio.h> ][]; #define inf 0xffffff; void floyed(int n) { int i,j,k; ;k<n;k++) { ;i ...
- BZOJ1050 [HAOI2006]旅行
其实这道题根本不用最短路算法... 我们可以就把边从小到大排序,那么只需要枚举大小两个端点,把中间的边都加进去判断联通性即可. 判断联通性显然用的是并查集. #include <cstdio&g ...
- mysql in 子查询 效率慢 优化(转)
mysql in 子查询 效率慢 优化(转) 现在的CMS系统.博客系统.BBS等都喜欢使用标签tag作交叉链接,因此我也尝鲜用了下.但用了后发现我想查询某个tag的文章列表时速度很慢,达到5秒之久! ...
- LVS-三种负载均衡方式比较
1.什么是LVS? 首 先简单介绍一下LVS (Linux Virtual Server)到底是什么东西,其实它是一种集群(Cluster)技术,采用IP负载均衡技术和 基于内容请求分发技术.调度器具 ...