CF1277B.Make Them Odd

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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).

有 nn 个正整数 a1,a2,…,ana_1, a_2, \dots, a_n。每次操作中,你可以任选一个偶数值 cc,并将数组中所有等于 cc 的元素全部除以 22。

例如,若 a=[6,8,12,6,3,12]a=[6,8,12,6,3,12],你选择 c=6c=6,则执行一次操作后,aa 变为 a=[3,8,12,3,3,12]a=[3,8,12,3,3,12]。

你需要求出将 aa 变换为仅含奇数的数组(即每个元素均不能被 22 整除)所需的最少操作次数。

输入格式

The first line of the input contains one integer tt (1≤t≤1041 \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 (1≤n≤2⋅1051 \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 (1≤ai≤1091 \le a_i \le 10^9).

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

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示输入中测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot10^5),表示序列 aa 中整数的个数。第二行包含 nn 个正整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

输入中所有测试用例的 nn 值之和不超过 2⋅1052\cdot10^5。

输出格式

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).

对于 tt 个测试用例,请按输入中测试用例的顺序输出答案。每个测试用例的答案是使该测试用例中所有数字变为奇数(即不能被 22 整除)所需的最少操作次数。

输入输出样例

  • 输入#1

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

    输出#1

    4
    10
    4
    0

说明/提示

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.

在示例的第一个测试用例中,最优的操作序列如下所示:

  • 操作前,a=[40,6,40,3,20,1]a=[40, 6, 40, 3, 20, 1];
  • 选择 c=6c=6;
  • 此时 a=[40,3,40,3,20,1]a=[40, 3, 40, 3, 20, 1];
  • 选择 c=40c=40;
  • 此时 a=[20,3,20,3,20,1]a=[20, 3, 20, 3, 20, 1];
  • 选择 c=20c=20;
  • 此时 a=[10,3,10,3,10,1]a=[10, 3, 10, 3, 10, 1];
  • 选择 c=10c=10;
  • 此时 a=[5,3,5,3,5,1]a=[5, 3, 5, 3, 5, 1] —— 所有数均为奇数。

因此,经过 44 次操作后,所有数均变为奇数。在 33 次或更少的操作内,无法使所有数都变为奇数。

输入解题思路,AI测评打分。不知道怎么写?

首页