fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. /**
  5.  * Created by Shreyans Sheth [bholagabbar] on 8/29/2015 at 10:21 PM using IntelliJ IDEA (Fast IO Template)
  6.  */
  7.  
  8. class Ideone
  9. {
  10. public static void main(String[] args) throws Exception
  11. {
  12. //System.setIn(new FileInputStream("E:/Shreyans/Documents/Code/CODE/src/Stdin_File_Read.txt"));
  13. InputReader in = new InputReader(System.in);
  14. OutputWriter out = new OutputWriter(System.out);
  15. int n=in.readInt();
  16. long []a =new long[n];
  17. long max=Long.MIN_VALUE;
  18. for(int i=0;i<n;i++)
  19. {
  20. a[i]=in.readInt();
  21. max=Math.max(a[i],max);
  22. }
  23. HashMap<Long,Long>hm=new HashMap<Long, Long>();
  24. for(int i=0;i<n;i++)
  25. {
  26. long x=a[i];
  27. HashSet<Long>vis=new HashSet<Long>();
  28. Queue<Long> q=new LinkedList<Long>();
  29. q.add(x);
  30. while(!q.isEmpty())
  31. {
  32. long cv=q.poll();
  33. if(!vis.contains(cv)&& cv<=1000000000)
  34. {
  35. vis.add(cv);
  36. if(!hm.containsKey(cv))
  37. hm.put(cv,(long)1);
  38. else
  39. hm.put(cv,hm.get(cv)+1);
  40. long i1=cv*2;
  41. long i2=cv*3;
  42. if(i1<=1000000000)
  43. q.add(i1);
  44. if(i2<=1000000000)
  45. q.add(i2);
  46. }
  47. }
  48. }
  49. for(long i:hm.keySet())
  50. {
  51. if(hm.get(i)!=n)
  52. {
  53. out.printLine("No");
  54. return;
  55. }
  56. }
  57. out.printLine("Yes");
  58. }
  59.  
  60. //FAST IO
  61. private static class InputReader
  62. {
  63. private InputStream stream;
  64. private byte[] buf = new byte[1024];
  65. private int curChar;
  66. private int numChars;
  67. private SpaceCharFilter filter;
  68.  
  69. public InputReader(InputStream stream)
  70. {
  71. this.stream = stream;
  72. }
  73.  
  74. public int read()
  75. {
  76. if (numChars == -1)
  77. throw new InputMismatchException();
  78. if (curChar >= numChars)
  79. {
  80. curChar = 0;
  81. try
  82. {
  83. numChars = stream.read(buf);
  84. } catch (IOException e)
  85. {
  86. throw new InputMismatchException();
  87. }
  88. if (numChars <= 0)
  89. return -1;
  90. }
  91. return buf[curChar++];
  92. }
  93.  
  94. public int readInt()
  95. {
  96. int c = read();
  97. while (isSpaceChar(c))
  98. c = read();
  99. int sgn = 1;
  100. if (c == '-')
  101. {
  102. sgn = -1;
  103. c = read();
  104. }
  105. int res = 0;
  106. do
  107. {
  108. if (c < '0' || c > '9')
  109. throw new InputMismatchException();
  110. res *= 10;
  111. res += c - '0';
  112. c = read();
  113. } while (!isSpaceChar(c));
  114. return res * sgn;
  115. }
  116.  
  117. public String readString()
  118. {
  119. int c = read();
  120. while (isSpaceChar(c))
  121. c = read();
  122. StringBuilder res = new StringBuilder();
  123. do
  124. {
  125. res.appendCodePoint(c);
  126. c = read();
  127. } while (!isSpaceChar(c));
  128. return res.toString();
  129. }
  130.  
  131. public double readDouble()
  132. {
  133. int c = read();
  134. while (isSpaceChar(c))
  135. c = read();
  136. int sgn = 1;
  137. if (c == '-')
  138. {
  139. sgn = -1;
  140. c = read();
  141. }
  142. double res = 0;
  143. while (!isSpaceChar(c) && c != '.')
  144. {
  145. if (c == 'e' || c == 'E')
  146. return res * Math.pow(10, readInt());
  147. if (c < '0' || c > '9')
  148. throw new InputMismatchException();
  149. res *= 10;
  150. res += c - '0';
  151. c = read();
  152. }
  153. if (c == '.')
  154. {
  155. c = read();
  156. double m = 1;
  157. while (!isSpaceChar(c))
  158. {
  159. if (c == 'e' || c == 'E')
  160. return res * Math.pow(10, readInt());
  161. if (c < '0' || c > '9')
  162. throw new InputMismatchException();
  163. m /= 10;
  164. res += (c - '0') * m;
  165. c = read();
  166. }
  167. }
  168. return res * sgn;
  169. }
  170.  
  171. public boolean isSpaceChar(int c)
  172. {
  173. if (filter != null)
  174. return filter.isSpaceChar(c);
  175. return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  176. }
  177.  
  178. public String next()
  179. {
  180. return readString();
  181. }
  182.  
  183. public interface SpaceCharFilter
  184. {
  185. public boolean isSpaceChar(int ch);
  186. }
  187. }
  188.  
  189. private static class OutputWriter
  190. {
  191. private final PrintWriter writer;
  192.  
  193. public OutputWriter(OutputStream outputStream)
  194. {
  195. writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
  196. }
  197.  
  198. public OutputWriter(Writer writer)
  199. {
  200. this.writer = new PrintWriter(writer);
  201. }
  202.  
  203. public void print(Object... objects)
  204. {
  205. for (int i = 0; i < objects.length; i++)
  206. {
  207. if (i != 0)
  208. writer.print(' ');
  209. writer.print(objects[i]);
  210. }
  211. writer.flush();
  212. }
  213.  
  214. public void printLine(Object... objects)
  215. {
  216. print(objects);
  217. writer.println();
  218. writer.flush();
  219. }
  220.  
  221. public void close()
  222. {
  223. writer.close();
  224. }
  225.  
  226. public void flush()
  227. {
  228. writer.flush();
  229. }
  230. }
  231. }
Success #stdin #stdout 0.11s 320512KB
stdin
2
2 3
stdout
No