F. GZP and Pokergzp often plays games with his friends. Today They went to a board game. There is n players (including GZP) and all of them has some virtual money on the table.< Span id= "mathjax-span-2" class= "Mrow" > i th of them has Ai yuan. Each player can double he virtual wealth any number of times and triple he virtual wealth any number of times. The game has a big prize for making wealth of all players equal. Is it possible for GZP and he friends to win the big prize? Inputthe input consists of several test cases. First line of input contains an integer n ( 2≤n≤10^5), the number of players.The second line contains n integer numbersa1,a2,?,an ( 1≤ai≤10^9)-the virtual money of players.Outputfor each test case, print a line. " Yes "(without the quotes) if players can make their wealth equal, or" No "otherwise. Sample Input
475 150 75 503100 150 250
Sample Output
YesNo
Test Instructions :
Ask whether these numbers can be transformed into the same number, transformed to multiply by 2 or 3, by any number of times;
Ideas :
Temp=a[i]*2^x*3*y;
can find
A[I]*2^X*3*Y=A[J];
The X and y here are integers; then you can search for it;
AC code :
#include <bits/stdc++.h>using namespacestd;#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong LongLL;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);Const intinf=0x3f3f3f3f;Const intn=1e5+5;intN; LL A[n];map<ll,int>MP;intDFS (LL x) {mp[x]=1; if(2*x<=3e9+7&&!mp[2*x]) {DFS (2*x); } if(3*x<=3e9+7&&!mp[3*x]) {DFS (3*x); } if(%2==0&&!mp[x/2]) {DFS (x/2); } if(%3==0&&!mp[x/3]) {DFS (x/3); }}intsolve () { for(intI=2; i<=n;i++) { if(!Mp[a[i]]) {printf ("no\n"); return 0; }} printf ("yes\n"); return 0;}intMain () { while(SCANF ("%d", &n)! =EOF) {mp.clear (); Riep (n) {scanf ("%lld",&A[i]); } DFS (a[1]); Solve (); } return 0;}
Simon GZP and Poker