luogu CF484A Bits |數學

题意翻译

  • (n)组询问,每次给出一个区间(l, r),你需要输出在这个区间内二进制表示中1的个数最多的数

  • 如有多个答案,输出最小的那个

  • ((n leq10^4, 0leq 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
",l);
	}
}

原文地址:https://www.cnblogs.com/naruto-mzx/p/12689500.html