Minimum divide by 2 operations required to make GCD odd for given Array | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minimumOperations ( int arr [ ] , int N ) { int mini = INT_MAX ; 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 ; } int main ( ) { int arr [ ] = { 4 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimumOperations ( arr , N ) ; return 0 ; }