Codeforces Round 1099 (Div. 2)
C
花栗鼠 Theo 与相等
Chipmunk Theo and Equality
Codeforces
1400
原题
← BD →

花栗鼠 Theo 与相等AI (CI翻译)

While exploring the depths of the Internet, Theodore the chipmunk found a very interesting sequence of positive integers and decided to play with it.

在探索互联网深处时,花栗鼠 Theodore 发现了一个非常有趣的正整数序列,于是决定用它来做些尝试。AI (CI翻译)

In one operation, he chooses an element of the sequence and performs the following action:

每次操作中,他会选择序列中的一个元素,并执行以下操作:AI (CI翻译)

  • If the chosen element is even, he divides it by 2.
  • If the chosen element is odd, he increases it by 1.
  • 如果选中的元素是偶数,就将它除以 2。
  • 如果选中的元素是奇数,就将它加 1。
AI (CI翻译)

Theo really loves equality, so he wants to make all numbers in the sequence equal (otherwise, some numbers might feel offended). Since he needs to plan his lunch time, help him determine the minimum number of operations required to make all numbers equal.

Theo 非常喜欢相等,因此他想让序列中的所有数字都相等(否则,某些数字可能会觉得受到了冒犯)。他还需要安排午餐时间,请你帮他求出使所有数字相等所需的最少操作次数。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个输入包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the sequence.

每个测试用例的第一行包含一个整数 $n$($1 \le n \le 10^5$),表示序列的长度。AI (CI翻译)

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the sequence.

第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \le a_i \le 10^9$),表示序列中的元素。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

保证所有测试用例的 $n$ 之和不超过 $10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output a single integer — the minimum number of operations Theo needs to make all numbers in the sequence equal.

对于每个测试用例,输出一个整数,表示 Theo 使序列中的所有数字相等所需的最少操作次数。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, we have a sequence: $[3, 2, 4]$

在第一个测试用例中,序列为:$[3, 2, 4]$AI (CI翻译)

One possible sequence of operations: $$ [\textbf{3}, 2, 4] \rightarrow [\textbf{4}, 2, 4] \rightarrow [2, 2, \textbf{4}] \rightarrow [2, 2, 2] $$ (Operations are performed on numbers shown in bold.)

一种可能的操作序列为:$$ [\textbf{3}, 2, 4] \rightarrow [\textbf{4}, 2, 4] \rightarrow [2, 2, \textbf{4}] \rightarrow [2, 2, 2] $$(每次操作针对加粗显示的数字。)AI (CI翻译)

In the second test case, the sequence is: $[3, 6, 7, 16, 8, 8, 7]$

在第二个测试用例中,序列为:$[3, 6, 7, 16, 8, 8, 7]$AI (CI翻译)

Possible operations:

可能的操作如下:AI (CI翻译)

  • Perform the operation once on the 1st element: $3 \rightarrow 4$
  • Perform the operation twice on the 2nd element: $6 \rightarrow 3 \rightarrow 4$
  • Perform the operation twice on the 4th element: $7 \rightarrow 8 \rightarrow 4$
  • Perform the operation twice on the 5th element: $16 \rightarrow 8 \rightarrow 4$
  • Perform the operation once on the 6th element: $8 \rightarrow 4$
  • Perform the operation once on the 7th element: $8 \rightarrow 4$
  • Perform the operation twice on the 8th element: $7 \rightarrow 8 \rightarrow 4$
  • 对第 1 个元素操作一次:$3 \rightarrow 4$
  • 对第 2 个元素操作两次:$6 \rightarrow 3 \rightarrow 4$
  • 对第 4 个元素操作两次:$7 \rightarrow 8 \rightarrow 4$
  • 对第 5 个元素操作两次:$16 \rightarrow 8 \rightarrow 4$
  • 对第 6 个元素操作一次:$8 \rightarrow 4$
  • 对第 7 个元素操作一次:$8 \rightarrow 4$
  • 对第 8 个元素操作两次:$7 \rightarrow 8 \rightarrow 4$
AI (CI翻译)

After these $11$ operations, all elements become $4$.

经过这 $11$ 次操作后,所有元素都变成了 $4$。AI (CI翻译)

样例

Input #1
5
3
3 2 4
7
3 6 7 16 8 8 7
3
1 4 2
5
10 10 10 10 10
6
1 1 3 1 1 1
Output #1
3
11
2
0
3
InputCopy OutputCopy
题目信息
题号
2231C
时间限制
2 s
内存限制
512 MB
标签
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。