
Sample 1
| Inputcopy | Outputcopy |
|---|---|
3 2 5 17 |
1 3 15 |
Note
In the first testcase, the maximum value for which the continuous & operation gives 0 value, is 1.
In the second testcase, 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≠05&4≠0,
- 5&4&3=05&4&3=0.
Hence, 3 is the answer.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n,a=1;
scanf("%d", &n);
while(a<=n/2)
{
a*=2;
}
printf("%d\n", a-1);
}
return 0;
}
这篇文章介绍了一个编程问题,涉及找到使`连续&操作`结果为0的整数n的最大值。通过举例和代码实现,解释了如何通过二进制倍增法求解。
9286

被折叠的 条评论
为什么被折叠?



