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 ...
随机推荐
- 转:Java NIO系列教程(三) Buffer
Java NIO中的Buffer用于和NIO通道进行交互.如你所知,数据是从通道读入缓冲区,从缓冲区写入到通道中的. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO ...
- RTMP流媒体播放过程(转)
本文描述了从打开一个RTMP流媒体到视音频数据开始播放的全过程. 注意:RTMP中的逻辑结构 RTMP协议规定,播放一个流媒体有两个前提步骤:第一步,建立一个网络连接(NetConnection):第 ...
- jQuery特效
基础特效 方法 描述 hide() 立即隐藏jQuery对象内的所有元素 hide(time).hide(time, easing) 在指定的时间内以动画方式隐藏jQuery对象内的所有元素,并可选一 ...
- CF360B Levko and Array (二分查找+DP)
链接:CF360B 题目: B. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes i ...
- make_head,,,pop_head,,,push_head,,,sort_head..
STL中,有很多的排序函数模板供我们调用,省去我们自己编写一些排序过程的麻烦.本文是一篇关于STL中堆排序的一个介绍. 本文涉及的几个函数如下:make_heap(), push_heap(), po ...
- exFAT是支持Mac和Win的
exFAT是支持Mac和Win的 转自: http://bbs.feng.com/read-htm-tid-8214017.html
- JVM调优浅谈
1.数据类型 java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:它代表的值就是数值本身,而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对象本 ...
- 如何用ndk-stack察看android崩溃堆栈
前提:要打开eclipse的LogCat窗口 1.保存log,先要选中eclipse的LogCat的所有行,点击保存,假设保存到了/User/mac/Desktop/log.txt 2.找到你的so( ...
- Ubuntu下装QQ2014
1.首先我们需要下载一个 deb的 Wine QQ安装包 qq2014官方下载:http://www.longene.org/download/WineQQ2013SP6-20140102-Longe ...
- UVALive 7270 Osu! Master (阅读理解题)
题目:传送门. 题意:阅读理解题,是一个osu的游戏,问得分.把题目翻译过来就是如果出现S或者BC后面跟的是1,ans就加1. #include <iostream> #include & ...