human
Minimum operations required to make every element greater than or equal to K | Function to calculate gcd of two numbers.
function to get minimum operation needed.
The priority queue holds a minimum element in the top position.
push value one by one from the given array.
store count of minimum operation needed.
All elements are now >= k.
It is impossible to make as there are no sufficient elements available.
Take two smallest elements and replace them by their LCM first smallest element.
Second smallest element.
Increment the count.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to minimum operations required to make every element greater than or equal to K and the other steps required.
 def gcd ( a , b ) :
	if ( a == 0 ) :
	return b
	return gcd ( b % a , a )
def FindMinOperation ( a , n , k ) :
	Q = [ ]
	for i in range ( 0 , n ) :
	Q . append ( a [ i ] )
	Q . sort ( )
	ans = 0
	while ( True ) :
	if ( Q [ 0 ] >= k ) :
		break
	if ( len ( Q ) < 2 ) :
		return - 1
	x = Q [ 0 ]
	Q . pop ( 0 )
	y = Q [ 0 ]
	Q . pop ( 0 )
	z = ( x * y ) // gcd ( x , y )
	Q . append ( z )
	Q . sort ( )
	ans += 1
	return ans
a = [ 3 , 5 , 7 , 6 , 8 ]
k = 8
n = len ( a )
print ( FindMinOperation ( a , n , k ) )