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/problem/A
Description
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 Input
4
75 150 75 50
Sample Output
Yes
HINT
题意
给你n个数,你可以把操作任意一个数,使他翻倍或者翻三倍无数次,问你是否可以让所有数都相同
题解:
假设最后变成了K,那么K=2^x+3^y+tmp
所以把所有数都按照2和3分解之后,只要剩下的数都是tmp,那就是yes
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
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 a[maxn];
int check(ll x)
{
if(x==)
return ;
if(x==)
return ;
if(x==)
return ;
if(x%==)
return check(x/);
if(x%==)
return check(x/);
return ;
}
int n;
ll gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
int main()
{
n=read();
for(int i=;i<n;i++)
a[i]=read();
sort(a,a+n);
ll tmp = a[];
for(int i=;i<n;i++)
{
tmp = gcd(tmp,a[i]);
}
for(int i=;i<n;i++)
{
if(!check(a[i]/tmp))
{
cout<<"No"<<endl;
return ;
}
}
cout<<"Yes"<<endl;
}
最新文章
- 【html+css】关于页面布局中遇到的问题记录
- pd name与comment互换,或者code互换,总之互换
- pt-diskstats 报错 Can&#39;t locate Time/HiRes.pm in @INC
- Redis和Memcache的区别分析
- ios添加方法快捷方式
- [vijos P1595] 学校网络
- 基于UltraVNC实现客户端远程控制
- 邮件工具类--EmailUtil
- IOS 学习笔记 2015-04-09 0C-SQLite 数据存储
- bzoj 2631: tree 动态树+常数优化
- 二、MLlib统计指标之关联/抽样/汇总
- 把自己的程序打成jar包,让别人调用
- U3D navmesh寻路简单示范
- POJ 2635 The Embarrassed Cryptographer 高精度
- Java生成CSV文件
- python每天一个小练习-强壮的密码
- CSS都有哪些选择器?
- Python Django CMDB项目实战之-2创建APP、建模(models.py)、数据库同步、高级URL、前端页面展示数据库中数据
- 【转载】Win10系统如何设置所有程序默认以管理员身份运行?
- Quartus II 中 Verilog 常见警告/错误汇总
热门文章
- MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存
- POJ 2253 Difference of Clustering
- [Papers]NSE, $u_3$, Lebesgue space [Kukavica-Ziane, Nonlinearity, 2006]
- Object类介绍
- <;译>;Selenium Python Bindings 4 - Locating Eelements
- 使用DDMS测试安卓手机APP的性能(android)
- 从表中随机返回n条记录
- 使用Google Chart API绘制组合图
- bzoj 2843 极地旅行社(LCT)
- vim 操作