CF BUDDY
← Problems·

1259B · Make Them Odd

1200 · greedy, number theory

Problem: There are nn positive integers a1,a2,,ana_1, a_2, \dots, a_n. For the one move you can choose any even value cc and divide by two all elements that equal cc.

For example, if a=[6,8,12,6,3,12]a=[6,8,12,6,3,12] and you choose c=6c=6, and aa is transformed into a=[3,8,12,3,3,12]a=[3,8,12,3,3,12] after the move.

You need to find the minimal number of moves for transforming aa to an array of only odd integers (each element shouldn't be divisible by 22).

Input Format: The first line of the input contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases in the input. Then tt test cases follow.

The first line of a test case contains nn (1n21051 \le n \le 2\cdot10^5) — the number of integers in the sequence aa. The second line contains positive integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9).

The sum of nn for all test cases in the input doesn't exceed 21052\cdot10^5.

Output Format: For tt test cases print the answers in the order of test cases in the input. The answer for the test case is the minimal number of moves needed to make all numbers in the test case odd (i.e. not divisible by 22).

Note: In the first test case of the example, the optimal sequence of moves can be as follows:

  • before making moves a=[40,6,40,3,20,1]a=[40, 6, 40, 3, 20, 1];
  • choose c=6c=6;
  • now a=[40,3,40,3,20,1]a=[40, 3, 40, 3, 20, 1];
  • choose c=40c=40;
  • now a=[20,3,20,3,20,1]a=[20, 3, 20, 3, 20, 1];
  • choose c=20c=20;
  • now a=[10,3,10,3,10,1]a=[10, 3, 10, 3, 10, 1];
  • choose c=10c=10;
  • now a=[5,3,5,3,5,1]a=[5, 3, 5, 3, 5, 1] — all numbers are odd.

Thus, all numbers became odd after 44 moves. In 33 or fewer moves, you cannot make them all odd.

Sample Cases

Case 1

Input

4
6
40 6 40 3 20 1
1
1024
4
2 4 8 16
3
3 1 7

Output

4
10
4
0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback