『题解』CodeForces CF1527A And Then There Were K
题目传送门
题目大意
给定一个正整数
思路
先来手算一下答案是啥。
以
进行一下操作:
1111&(1111-1 )=1110;1110&(1111-2 )=1100;1100&(1111-3 )=1100;1100&(1111-4 )=1000;1000&(1111-5 )=1000;1000&(1111-6 )=1000;1000&(1111-7 )=1000;1000&(1111-8 )=0000;
到
可以推断出,从
最终答案为:(1<<(int)log2(n))-1。
代码
#include <iostream>
#include <cmath>
using namespace std;
int t,n;
int main(){
cin >> t;
while(t--){
cin >> n;
cout << (1<<(int)log2(n))-1 << endl; // 直接套
}
return 0;
}