【CodeForces - 574C】Bear and Poker(思维,剪枝,数学)

246 篇文章 1 订阅
46 篇文章 0 订阅

题干:

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.

Examples

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.

题目大意:

   最开始每个人都有一个值,任何一个人都可以将自己的值变成原来的两倍或三倍,问能不能让所有人的值都相等。

解题报告:

   除了暴力想不到别的方法了,,随便交一发没想到a了。。不过不会算时间复杂度?感觉o(n^2)级别的吧?本来想先把a[i]都存下,然后再o(n)判断一遍的,但是感觉可能会超时?(毕竟不会算复杂度)于是采取边处理便判断的方式,找到NO的就直接输出然后结束程序了,算是一种剪枝?

   至于这道题的思路,也挺好想的吧算是。我们分析最终得数,如果最终得数要相同,因为可以乘任意次,也就是说最终得数中可以包含任意个3和2做因子,于是我们把这些因子除去,看剩下的数字是否是一样的,也就可以判断最终的答案是否是一样的。

法2:人选两个人出来,a1,a2,按题意方法要有所以直接判断a1,a2能不能不断的乘2,3得到两个数的最小公倍数就好了。

AC代码:

//暴力?
#include<bits/stdc++.h>

using namespace std;
const int MAX = 1e5 +5;
int a[MAX];
int main()
{
	int n;
	cin>>n;
	for(int i = 1; i<=n; i++) scanf("%d",a+i);
	for(int i = 1; i<=n; i++) {
		while(a[i]%6==0) a[i]/=6;
		while(a[i]%2==0) a[i]/=2;
		while(a[i]%3==0) a[i]/=3;
		if(i==1) continue;
		if(a[i] != a[i-1]) {
			puts("No");return 0;
		}
	}
	puts("Yes");
	return 0 ;
 } 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值