Alice and Apple

4.3

3 votes
, C++, Basic Math, Observation, Math
Problem

Alice has N apples in a straight line. The ith apple has the tastiness value of A[i], where 0<=i<N. In one operation, you can do any of the following operations.

  1. You can choose apple at any position i, 0<=i<N. If its tastiness value A[i] is divisible by 2, divide A[i]/2.
  2. You can choose apple at any position i, 0<=i<N. If its tastiness value A[i] is divisible by 3, divide A[i]/3.

Alice gives you the task of making the tastiness value of all apples equal. Print Yes if you can complete the task, else print No.

Input Format:

  • The first line contains an integer T, denoting the number of test cases.
  • The first line of each test case contains N, denoting the size of the array A.
  • The second line of each test case contains N space-separated integers denoting the elements of the array A.

Output Format:

For each test case, print Yes if you can complete the task, else print No.

Constraints:

1<=T<=10

1<=N<=105

0<=A[i]<=109

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

First test case:

In the first operation, choose apple at index 2. Divide its tastiness value by 2. So, A[2] will now be 1. In the second operation, choose apple at index 3. Divide its tastiness value by 2. So, A[3] will now be 1. The array A becomes [1,1,1,1]. Hence, the answer is Yes.

Second test case:

It is not possible to make the tastiness value of all apples equal. Hence, the answer is No.

Editor Image

?