human
Smallest perfect Cube divisible by all elements of an array | Function to return the gcd of two numbers.
Function to return the lcm of all the elements of the array.
To calculate lcm of two numbers multiply them and divide the result by gcd of both the numbers.
Return the LCM of the array elements.
Function to return the smallest perfect cube divisible by all the elements of arr [ ].
LCM of all the elements of arr [ ].
If 2 divides lcm cnt number of times.
Check all the numbers that divide lcm.
Return the answer.
Driver code"
How can the above be solved in Python?
 ... Can you provide a code to smallest perfect Cube divisible by all elements of an array and the other steps required?
assistant
#Here is code to smallest perfect Cube divisible by all elements of an array and the other steps required.
 def gcd ( a , b ) :
	if ( b == 0 ) :
		return a
	else :
		return gcd ( b , a % b )
def lcmOfArray ( arr , n ) :
	if ( n < 1 ) :
		return 0
	lcm = arr [ 0 ]
	for i in range ( n ) :
		lcm = ( lcm * arr [ i ] ) // gcd ( lcm , arr [ i ] ) ;
	return lcm
def minPerfectCube ( arr , n ) :
	lcm = lcmOfArray ( arr , n )
	minPerfectCube = lcm
	cnt = 0
	while ( lcm > 1 and lcm % 2 == 0 ) :
		cnt += 1
		lcm //= 2
	if ( cnt % 3 == 2 ) :
		minPerfectCube *= 2
	elif ( cnt % 3 == 1 ) :
		minPerfectCube *= 4
	i = 3
	while ( lcm > 1 ) :
		cnt = 0
		while ( lcm % i == 0 ) :
			cnt += 1
			lcm //= i
		if ( cnt % 3 == 1 ) :
			minPerfectCube *= i * i
		elif ( cnt % 3 == 2 ) :
			minPerfectCube *= i
		i += 2
	return minPerfectCube
if __name__ == " _ _ main _ _ " :
	arr = [ 10 , 125 , 14 , 42 , 100 ]
	n = len ( arr )
	print ( minPerfectCube ( arr , n ) )