给一个整数D,求比D大的且二进制含有1的个数在s1---s2之间的最小的整数
从高位往低位找D二进制中第一个从0到1的那个位,之后就尽可能地把剩下的1全部填在低位上,然后所有情况中取个最小值
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
#define rd(x) scanf("%d",&x)
#define rdd(x,y) scanf("%d%d",&x,&y)
#define rddd(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rdddd(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define rds(s) scanf("%s",s)
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
const int N = 1e5+10;
const int M=2000;
const int inf=0x3f3f3f3f;
const double eps=1e-9;
int MOD=1e9+7;
int cas=1;
int n,m,k,q;
int sgn(double x){return x<-eps?-1:x<eps?0:1;}
LL d;
int l,r;
LL col[35];
LL sum[35];
int a[35];
int main()
{
#ifndef ONLINE_JUDGE
freopen("aaa","r",stdin);
//freopen("bbb","w",stdout);
#endif
int T;
rd(T);
col[0]=1;
sum[0]=0;
for(int i=1;i<=32;i++) {
col[i]=col[i-1]*2;
}
for(int i=1;i<=32;i++){
sum[i]=sum[i-1]+col[i-1];
}
while(T--){
scanf("%I64d%d%d",&d,&l,&r);
int cnt=0;
LL x=d;
memset(a,0,sizeof a);
while(x){
a[cnt++]=x%2;
x/=2;
}
int before=0;
LL tmp=0;
LL ans=col[32];
for(int i=31;i>=0;i--){
if(a[i]==0){
if(before+1>=l && before+1<=r){ans=min(ans,tmp+col[i]);}
else if(before+1<l && (l-before-1)<=i){
ans=min(ans,tmp+col[i]+sum[l-before-1]);
}
}
if(a[i]==1){
before++;
tmp+=col[i];
}
}
cout<<"Case #"<<cas++<<": "<<ans<<endl;
}
return 0;
}