luogu CF484A Bits | Mathematics

Title translation

  • \ (n \) group query, each time an interval \ (l, r \) is given , you need to output the number with the largest number of 1s in the binary representation in this interval

  • If there are multiple answers, output the smallest one

  • \((n \leq10^4, 0\leq l, r \leq10^{18})\)


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1e9+7,N=2e5+10;
#define int long long
int n,l,r;
signed main(){
	cin>>n;
	while(n--){
		scanf("%lld%lld",&l,&r);
		for(int i=1;(l|i)<=r;i<<=1)l|=i;
		printf("%lld\n",l);
	}
}

Guess you like

Origin www.cnblogs.com/naruto-mzx/p/12689500.html