Problem 3822 --And Then There Were K

3822: And Then There Were K

"
Time Limit $1$ 秒/Second(s) Memory Limit $128$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签

Given an integer n, find the maximum value of integer k such that the following condition holds:

n & (n−1) & (n−2) & (n−3) & ... (k) = where & denotes the bitwise AND operation.

The first line contains a single integer t (1≤t≤3⋅104). Then t test cases follow.

The first line of each test case contains a single integer n (1≤n≤109).

For each test case, output a single integer — the required integer k.
3
2
5
17
1
3
15

In the first test case, the maximum value for which the continuous & operation gives 0 value, is 1.

In the second test case, the maximum value for which the continuous & operation gives 0 value, is 3. No value greater then 3, say for example 4, will give the & sum 0.

  • 5&4≠0,
  • 5&4&3=0.

Hence, 3 is the answer.

推荐代码 查看3822 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$120 $ms] 只能过个样例~~~ 762091 2021-08-20 17:07:31
内存最少[$2488 $KB] 只能过个样例~~~ 762091 2021-08-20 17:07:31
第一AC 只能过个样例~~~ 762091 2021-08-20 17:07:31
第一挑战 只能过个样例~~~ 762091 2021-08-20 17:07:31

赛题来源/所属竞赛 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛