Problem:
Score : 900 points

Problem Statement

Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive).
How many possible candidates of the value of Nukes's integer there are?

Constraints

1 ≤ A ≤ B < 2^{60}

A and B are integers.

Input

The input is given from Standard Input in the following format:

A
B

Output

Print the number of possible candidates of the value of Nukes's integer.

Sample Input 1

7
9

Sample Output 1

4

In this case, A=7 and B=9. There are four integers that can be represented as the bitwise OR of a non-empty subset of {7, 8, 9}: 7, 8, 9 and 15.

Sample Input 2

65
98

Sample Output 2

63

Sample Input 3

271828182845904523
314159265358979323

Sample Output 3

68833183630578410

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

LL A,B;

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	scanf("%lld %lld",&A,&B);
	if (A==B) {puts("1"); return 0;}
	LL r,k;
	LL ans=0,tmp=0;
	per(i,60,0) {
		LL t1=(1LL<<i)&A,t2=(1LL<<i)&B;
		if (t1!=t2) {r=i; break;}
		tmp+=(1LL<<i)&A;
	}
	LL T=(1LL<<r);
	A-=tmp,B-=tmp;
	ans+=T-A;
	per(i,r-1,0) if (B&(1LL<<i)) {k=i; break;}
	LL Q=(1LL<<(k+1))-1;
	ans+=Q+1;
	ans+=T-A;
	if (A<=Q) ans-=(Q-A+1);
	if (T-1<=Q) ans+=(Q-T+2);
		
	printf("%lld\n",ans);

	return 0;
}