Run
//Write a program to check can all number of an array be made equal in Java
import java.util.*;
public class Main
{
public static boolean make_equal(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
// Divide number by 2
while (arr[i] % 2 == 0)
arr[i] /= 2;
// Divide number by 3
while (arr[i] % 3 == 0)
arr[i] /= 3;
}
// Remaining numbers
for (int i = 1; i < n; i++)
if (arr[i] != arr[0]){
return false;
}
return true;
}
public static void main (String[] args)
{
int arr[] = { 50, 100, 75 };
int m = arr.length;
if (make_equal(arr, m))
System.out.print("Yes");
else
System.out.print("No");
}
}
def equal(a,l):
for i in range(l):
while a[i]%2==0:
a[i]/=2
while a[i]%3==0:
a[i]/=3
if a[i]!=a[0]:
return False
return True
a=list(map(int,input().split()))
l=len(a)
if equal(a,l):
print(“yes”)
else:
print(“no”)
#Python Program
size = int(input(“Enter array size: “))
arr = []
for i in range(size):
arr.append(int(input()))
for i in range(size):
while arr[i]%2 == 0:
arr[i] /= 2
while arr[i]%3 == 0:
arr[i] /= 3
for i in range(size):
if arr[i] != arr[0]:
print(“N0”)
break
else:
print(“Yes”)
———-CODE IN PYTHON————-
def equal(n):
for i in range(len(n)):
while(n[i]%2==0):
n[i] /= 2
while(n[i]%3==0):
n[i] /= 3
for i in range(len(n)):
if(n[i]!=n[0]):
return False
return True
n = list(map(int,input().split()))
if(equal(n)):
print(“Yes”)
else:
print(“No”)