-
Notifications
You must be signed in to change notification settings - Fork 765
/
Copy pathmakeEqual.java
40 lines (35 loc) · 873 Bytes
/
makeEqual.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package eteQuestionBank;
import java.util.*;
public class makeEqual {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
int[] arr = new int[n];
for(int i = 0; i<n; i++){
arr[i] = sc.nextInt();
}
if(ifEqual(arr)){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
static boolean ifEqual(int[] arr){
for(int i = 0; i<arr.length; i++){
while(arr[i]%2==0){
arr[i] = arr[i]/2;
}
while(arr[i]%3==0){
arr[i] = arr[i]/3;
}
}
for(int i = 1; i< arr.length; i++){
if(arr[i]!=arr[0]){
return false;
}
}
return true;
}
}