Alice and Apple

4.3

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

Alice has apples in a straight line. The apple has the tastiness value of , where . In one operation, you can do any of the following operations.

  1. You can choose apple at any position , . If its tastiness value is divisible by 2, divide .
  2. You can choose apple at any position , . If its tastiness value is divisible by 3, divide .

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

Input Format:

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

Output Format:

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

Constraints:

Sample Input
2
4
1 1 2 2
4
1 1 1 7
Sample Output
Yes
No
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

First test case:

In the first operation, choose apple at index . Divide its tastiness value by . So, will now be . In the second operation, choose apple at index . Divide its tastiness value by . So, will now be . The array becomes . Hence, the answer is .

Second test case:

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

Editor Image

?