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 ≤ 10^5), the number of players.
The second line contains n integer numbers a1, a2, …, an (1 ≤ ai ≤ 10^9) — the bids of players.
Output
Print “Yes” (without the quotes) if players can make their bids become equal, or “No” otherwise.
Sample Input
Input
4
75 150 75 50
Output
Yes
Input
3
100 150 250
Output
No
Hint
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.
题意:最开始每个人都有一个值,任何一个人都可以将自己的值变大两倍或3背,问能不能让所有人的值都相等。
解法:人选两个人出来,a1,a2,按题意方法要有
a1∗2n1∗3m1==a2∗2n2∗3m2==lcm
所以直接判断a1,a2能不能不断的乘2,3得到两个数的最小公倍数就好了。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL a[100005];
int n;
bool judge(){
for(int i=2;i<=n;i++){
LL bei=a[i-1]*a[i]/__gcd(a[i-1],a[i]);
LL F=bei/a[i-1],S=bei/a[i];
while(F%2==0) F/=2;
while(F%3==0) F/=3;
while(S%2==0) S/=2;
while(S%3==0) S/=3;
if(F!=1||S!=1) return false;
}
return true;
}
int main(){
while(cin>>n){
for(int i=1;i<=n;i++) cin>>a[i];
if(judge()==true) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}