Minimum divide by 2 operations required to make GCD odd for given Array | Java program for the above approach ; 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
class GFG { public static int minimumOperations ( int arr [ ] , int N ) { int mini = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; while ( arr [ i ] % 2 == 0 ) { arr [ i ] = arr [ i ] / 2 ; count ++ ; } if ( mini > count ) { mini = count ; } } return mini ; } public static void main ( String args [ ] ) { int arr [ ] = { 4 , 6 } ; int N = arr . length ; System . out . println ( minimumOperations ( arr , N ) ) ; } }