AtCoder Regular Contest++ 220
E
popcount ≥ K
AtCoder
⌀ 3583
原题
← D→

popcount ≥ KAI (CI翻译)

Problem Statement

You are given positive integers $N,C,K$.

Find the smallest positive integer $X$ satisfying $\displaystyle\min_{0\le i < N} \text{popcount}(X+Ci) \geq K$.

It can be proved that such a positive integer $X$ always exists.

You are given $T$ test cases; solve each of them.

What is popcount? For a non-negative integer $x$, $\operatorname{popcount}(x)$ is the number of $1$s in the binary representation of $x$. More formally, for a non-negative integer $x$ satisfying $\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace)$, we have $\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i$. For example, $13$ in binary is 1101, so we have $\operatorname{popcount}(13)=3$.

Constraints

  • $1\le T \le 10^5$
  • $1\le N\le 10^8$
  • $1\le C\le 30$
  • $1\le K\le 30$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

Each test case is given in the following format:

N C K

Output

Output the answers for the test cases in order, separated by newlines.

{"titleZh":"popcount ≥ K","bodyZh":"## 题目描述\n\n给定正整数 $N,C,K$。\n\n请找出满足 $\displaystyle\\min_{0\\le i < N} \\text{popcount}(X+Ci) \\geq K$ 的最小正整数 $X$。\n\n可以证明,这样的正整数 $X$ 始终存在。\n\n给定 $T$ 组测试数据,请分别求出每组的答案。\n\n什么是 popcount?对于非负整数 $x$,$\operatorname{popcount}(x)$ 表示 $x$ 的二进制表示中 $1$ 的个数。更正式地,对于满足 $\displaystyle x=\\sum _ {i=0} ^ \\infty b _ i2 ^ i\\ (b _ i\\in\\lbrace0,1\\rbrace)$ 的非负整数 $x$,有 $\displaystyle\\operatorname{popcount}(x)=\\sum _ {i=0} ^ \\infty b _ i$。例如,$13$ 的二进制表示为 1101,因此 $\operatorname{popcount}(13)=3$。\n\n## 约束条件\n\n- $1\\le T \\le 10^5$\n- $1\\le N\\le 10^8$\n- $1\\le C\\le 30$\n- $1\\le K\\le 30$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入按以下格式给出:\n\n\nT\n\\text{case}_1\n\\text{case}_2\n\\vdots\n\\text{case}_T\n`\n\n每组测试数据按以下格式给出:\n\n`\nN C K\n\n\n## 输出格式\n\n按顺序输出各组测试数据的答案,每个答案占一行。"}AI (CI翻译)

样例

Input #1
3
3 1 3
6 7 12
100000000 30 30
Output #1
13
32711
144115183780888607
Consider the first test case. $X=13$ satisfies the condition, as confirmed below: - When $i=0$: $\text{popcount}(X+Ci)=\text{popcount}(13)=3$ - When $i=1$: $\text{popcount}(X+Ci)=\text{popcount}(14)=3$ - When $i=2$: $\text{popcount}(X+Ci)=\text{popcount}(15)=4$ There is no positive integer smaller than $13$ satisfying the condition, so output $13$ on the first line.
题目信息
题号
arc220_e
时间限制
6 s
内存限制
1024 MB

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