- Arrays, GCD-LCM, HCF, Mathematical

Minimum divide by 2 operations required to make GCD odd for given Array

Given an array arr[] of N positive integers, the task is to find the minimum number of operations required to make the GCD of array element odd such that in each operation an array element can be divided by 2.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.Input: arr[] = {4, 6}Output: 1Explanation:Below are the operations performed:Operation 1: Divide the array element arr[0](= 4) by 2 modifies the array to {2, 6}.Operation 2: Divide the array element arr[0](= 2) by 2 modifies the array to {1, 6}.After the above operations, the GCD of the array elements is 1 which is odd. Therefore, the minimum number of operations required is 2.Input: arr[] = {2, 4, 1}Output: 0Approach: The given problem can be solved based on the observation by finding the count of powers of 2 for each array element and the minimum power of 2(say C) will give the minimum operations because after dividing that element by 2C the element becomes odd and that results in the GCD of the array as odd.Below is the implementation of the above approach:C++#include 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