human
What is a code to find an array element such that all elements are divisible by it and the other steps required given the following:
Find an array element such that all elements are divisible by it | Function to find the smallest element.
Function to find smallest num.
Find the smallest element.
Check if all array elements are divisible by smallest ..
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find an array element such that all elements are divisible by it and the other steps required.
 def min_element ( a ) :
	m = 10000000
	for i in range ( 0 , len ( a ) ) :
		if ( a [ i ] < m ) :
			m = a [ i ]
	return m
def findSmallest ( a , n ) :
	smallest = min_element ( a )
	for i in range ( 1 , n ) :
		if ( a [ i ] % smallest >= 1 ) :
			return - 1
	return smallest
a = [ 25 , 20 , 5 , 10 , 100 ]
n = len ( a )
print ( findSmallest ( a , n ) )