Odd GCD codechef solution
You are given an array consisting of integers. Your goal is to make the GCD of all the elements in the array an odd integer. To achieve this goal, you can do the following operation any number of times:
- Choose an index such that and set
You can choose an index multiple times during the operations. Find the minimum number of operations after which GCD of all the elements in the array becomes an odd integer.
Note: : Returns the largest integer that is less than or equal to (i.e rounds down to the nearest integer). For example, .
Input Format
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
Output Format
For each test case, print a single line containing one integer - the minimum number of operations after which GCD of all the elements in the array becomes an odd integer.
Constraints
- Sum of over all test cases does not exceed
Sample Input 1
3
3
2 3 5
2
4 6
3
4 12 24
Sample Output 1
0
1
2
Explanation
Test case : The GCD of all integers in the array is already , which is odd.
Test case : You choose the index and set . So the array becomes and the GCD of and is
Solution on python
Comments
Post a Comment