另一个 Popcount 问题AI (CI翻译)
You are given two integers $n$ and $k$.
你有两个整数 $n$ 和 $k$。AI (CI翻译)
Your task is to construct a sequence $a$ consisting of $k$ non-negative integers $a_1, a_2, \ldots, a_k$ such that:
你的任务是构造一个由 $k$ 个非负整数组成的序列 $a$,即 $a_1, a_2, \ldots, a_k$,满足:AI (CI翻译)
$\sum_{i=1}^{k} a_i \le n$- The total number of set bits, i.e.,
$\sum_{i=1}^{k} \operatorname{popcount}(a_i)$, is as large as possible.
$\sum_{i=1}^{k} a_i \le n$- 置位的总数,即
$\sum_{i=1}^{k} \operatorname{popcount}(a_i)$,尽可能大。
You only need to output the maximum possible value of $\sum_{i=1}^{k} \operatorname{popcount}(a_i)$.
你只需要输出 $\sum_{i=1}^{k} \operatorname{popcount}(a_i)$ 的最大可能值。AI (CI翻译)
Here, $\operatorname{popcount}(x)$ denotes the number of $1$ bits in the binary representation of $x$. For example, $\operatorname{popcount}(6) = \operatorname{popcount}((110)_2) = 2$, and $\operatorname{popcount}(0) = 0$.
其中,$\operatorname{popcount}(x)$ 表示 $x$ 的二进制表示中 $1$ 的个数。例如,$\operatorname{popcount}(6) = \operatorname{popcount}((110)_2) = 2$,且 $\operatorname{popcount}(0) = 0$。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^3$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^3$)。接下来给出各测试用例的描述。AI (CI翻译)
Each of the next $t$ lines contains two integers $n$ and $k$ ($1 \le n, k \le 10^6$) — the maximum allowed sum of the sequence and the length of the sequence, respectively.
接下来的 $t$ 行中,每行包含两个整数 $n$ 和 $k$($1 \le n, k \le 10^6$),分别表示序列元素之和的最大允许值和序列的长度。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output a single integer — the maximum possible value of $\sum_{i=1}^{k} \operatorname{popcount}(a_i)$.
对于每个测试用例,输出一个整数,即 $\sum_{i=1}^{k} \operatorname{popcount}(a_i)$ 的最大可能值。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, $n=2$ and $k=1$. We can choose $a = [1]$ or $a = [2]$. In both cases, the sum of popcounts is $1$.
在第一个测试用例中,$n=2$ 且 $k=1$。我们可以选择 $a = [1]$ 或 $a = [2]$。在这两种情况下,置位总数都是 $1$。AI (CI翻译)
In the second test case, $n=3$ and $k=1$. We can choose $a = [3]$, since $(3)_2 = (11)_2$, $\operatorname{popcount}(3) = 2$.
在第二个测试用例中,$n=3$ 且 $k=1$。我们可以选择 $a = [3]$,因为 $(3)_2 = (11)_2$,所以 $\operatorname{popcount}(3) = 2$。AI (CI翻译)
In the third test case, $n=6$ and $k=2$. We can choose $a = [3, 3]$. The sum is $3 + 3 = 6 \le 6$, and the total popcount is $\operatorname{popcount}(3) + \operatorname{popcount}(3) = 2 + 2 = 4$.
在第三个测试用例中,$n=6$ 且 $k=2$。我们可以选择 $a = [3, 3]$。其元素之和为 $3 + 3 = 6 \le 6$,置位总数为 $\operatorname{popcount}(3) + \operatorname{popcount}(3) = 2 + 2 = 4$。AI (CI翻译)
样例
6
2 1
3 1
6 2
14142 137205
1000000 100
1000000 1000000
1
2
4
14142
1322
1000000
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。