[Solution] Break the elements CodeChef Solution
Problem
Chef has an array of length . In one operation, Chef can choose any element and split it into two positive integers and such that .
Note that the length of array increases by after every operation.
Determine the minimum numbers of operations required by Chef to make parity of all the elements same.
It is guaranteed that parity of all the elements can be made equal after applying the above operation zero or more times.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer — the length of array .
- Next line contains space-separated integers - denoting the array .
Output Format
For each test case, output the minimum number of operations required to make parity of all elements same.
Explanation:
Test case : All the elements have the same parity since all are odd. Thus, we need zero operations.
Test case : In one operation, we can split the element to and such that . Thus, the array now becomes . All the elements have the same parity since all are odd. Thus, we need only one operation.
No comments:
Post a Comment