70分,wa后3点
#include<bits/stdc++.h>
using namespace std;
long long dp[50][50],lon,a[50],l,r;
int dfs(int pos,bool lim,int lead,int cha)
{
short temp=0;
if(pos==0) return cha>=0;
if(!lim&&!lead&&dp[pos][cha]!=-1) return dp[pos][cha];
long long res=0,up=lim?a[pos]:1;
for(int i=0;i<=up;i++){
if(i==0)
{
if(lead) temp=0;
else temp=1;
}
else temp=-1;
res+=dfs(pos-1,lim&(i==a[pos]),lead&(i==0),cha+temp);
}
if(!lim&&!lead) dp[pos][cha]=res;
return res;
}
int work(int u)
{
lon=0;
while(u) a[++lon]=u%2,u/=2;
memset(dp,-1,sizeof(dp));
return dfs(lon,1,1,0);
}
int main()
{
cin>>l>>r;
cout<<work(r)-work(l-1);
return 0;
}