AT_arc220_e.popcount ≥ K

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

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

Find the smallest positive integer XX satisfying min⁡0≤i<Npopcount(X+Ci)≥K\displaystyle\min_{0\le i < N} \text{popcount}(X+Ci) \geq K.

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

You are given TT test cases; solve each of them.

What is popcount?

For a non-negative integer xx, popcount⁡(x)\operatorname{popcount}(x) is the number of 11s in the binary representation of xx. More formally, for a non-negative integer xx satisfying x=∑i=0∞bi2i (bi∈{0,1})\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace), we have popcount⁡(x)=∑i=0∞bi\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i.

For example, 1313 in binary is 1101, so we have popcount⁡(13)=3\operatorname{popcount}(13)=3.

给定正整数 N,C,KN,C,K。

求满足 min⁡0≤i<Npopcount(X+Ci)≥K\displaystyle\min_{0\le i < N} \text{popcount}(X+Ci) \geq K 的最小正整数 XX。

可以证明,这样的正整数 XX 总是存在的。

你将得到 TT 组测试数据;请对每组数据求解。

什么是 popcount?

对于非负整数 xx,popcount⁡(x)\operatorname{popcount}(x) 表示 xx 的二进制表示中 11 的个数。更形式化地,若非负整数 xx 满足 x=∑i=0∞bi2i (bi∈{0,1})\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace),则定义 popcount⁡(x)=∑i=0∞bi\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i。

例如,1313 的二进制表示为 1101,因此 popcount⁡(13)=3\operatorname{popcount}(13)=3。

输入格式

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

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN CC KK

输入从标准输入中按以下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例按以下格式给出:

NN CC KK

输出格式

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

按顺序输出测试用例的答案,答案之间用换行符分隔。

输入输出样例

  • 输入#1

    3
    3 1 3
    6 7 12
    100000000 30 30

    输出#1

    13
    32711
    144115183780888607

说明/提示

Sample 1 Explanation:
Consider the first test case.

X=13X=13 satisfies the condition, as confirmed below:

  • When i=0i=0: popcount(X+Ci)=popcount(13)=3\text{popcount}(X+Ci)=\text{popcount}(13)=3
  • When i=1i=1: popcount(X+Ci)=popcount(14)=3\text{popcount}(X+Ci)=\text{popcount}(14)=3
  • When i=2i=2: popcount(X+Ci)=popcount(15)=4\text{popcount}(X+Ci)=\text{popcount}(15)=4

There is no positive integer smaller than 1313 satisfying the condition, so output 1313 on the first line.

Constraints

  • 1≤T≤1051\le T \le 10^5
  • 1≤N≤1081\le N\le 10^8
  • 1≤C≤301\le C\le 30
  • 1≤K≤301\le K\le 30
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

X=13X=13 满足条件,验证如下:

  • 当 i=0i=0 时:popcount(X+Ci)=popcount(13)=3\text{popcount}(X+Ci)=\text{popcount}(13)=3
  • 当 i=1i=1 时:popcount(X+Ci)=popcount(14)=3\text{popcount}(X+Ci)=\text{popcount}(14)=3
  • 当 i=2i=2 时:popcount(X+Ci)=popcount(15)=4\text{popcount}(X+Ci)=\text{popcount}(15)=4

不存在比 1313 更小的正整数满足该条件,因此第一行输出 1313。

约束条件

  • 1≤T≤1051\le T \le 10^5
  • 1≤N≤1081\le N\le 10^8
  • 1≤C≤301\le C\le 30
  • 1≤K≤301\le K\le 30
  • 所有输入值均为整数。

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

首页