EOJ 3303. 1 的个数最多的整数
1.ac代码
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<bitset>
typedef unsigned long long ull;
using namespace std;
int main(){
int n,j = 1;
ull a,b;
cin >> n;
while(j <= n){
cin >> a>> b;
int count = 0;
ull res = a;//最小值
bitset<70> bt(a);//将a设置为最小的bt
for(int i= 0;i<= 64;i++){
if(bt[i] == 0 ) bt[i]= 1;//设置为1
res = bt.to_ullong();
if(res > b ) {
bt[i] = 0;
res = bt.to_ullong();
break;
}
}
cout << "Case "<<j<<": "<<res << endl;
j++;
}
}