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: Runtime Error)

#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 65
#define LL long long
int a[MAXN],ra,b[MAXN],rb,flag;
LL ans,A,B;
LL Count(int i)
{
	LL ret=0;
	for(;i;i--)
		ret=ret*2+a[i];
	return ret;
}
int main()
{
	scanf("%lld%lld",&A,&B);
	ans=B-A+1;
	while(B)
	{
		b[++rb]=B&1;
		B>>=1;
	}
	while(A)
	{
		a[++ra]=A&1;
		A>>=1;
	}
	while(b[rb]==a[rb]&&rb>0) rb--,ra--;
	for(int i=rb-1;i;i--)
		if(b[i]==0&&a[i]==0)
		{
			ans+=1LL<<(i-1);
		}
		else if(b[i]==0&&a[i]==1)
		{
			if(flag) ans+=1LL<<(i-1);
			else
			{
				ans+=(1LL<<(i-1))-Count(i-1);
				while(b[i]==0&&i>0) i--;
				for(int j=i;j;j--)
					if(b[j]==0)
					{
						ans+=1LL<<(j-1);
					}
				break;
			}
		}
		else flag=1;
	printf("%lld\n",ans);
}