Minimum divide by 2 operations required to make GCD odd for given Array | python program for the above approac ; Function to find the minimum number of operations to make the GCD of the array odd ; Stores the minimum operations required ; Stores the powers of two for the current array element ; Dividing by 2 ; Increment the count ; Update the minimum operation required ; Return the result required ; Driver Code
INT_MAX = 2147483647 NEW_LINE def minimumOperations ( arr , N ) : NEW_LINE INDENT mini = INT_MAX NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT count = 0 NEW_LINE while ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT arr [ i ] = arr [ i ] // 2 NEW_LINE count += 1 NEW_LINE DEDENT if ( mini > count ) : NEW_LINE INDENT mini = count NEW_LINE DEDENT DEDENT return mini NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 4 , 6 ] NEW_LINE N = len ( arr ) NEW_LINE print ( minimumOperations ( arr , N ) ) NEW_LINE DEDENT