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)

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

LL dig(LL A) {
	int cnt = 0;
	while (A) {
		cnt++;
		A /= 2;
	}
	return cnt;
}

LL solve(LL A, LL B) {
	if (A == 0) {
		if (B == 0) return 1;
		return 1 + solve(A + 1, B);
	}

	if (A == B) return 1;
	if (A > B) return 0;

	// 0 < A < B
	
	LL dgA = dig(A), dgB = dig(B);
	if (dgA == dgB) {
		return solve(A - (1LL << (dgA - 1)), B - (1LL << (dgB - 1)));
	}

	LL ret = 0;
	for (int i = dgA + 1; i < dgB; i++) {
		ret += (1LL << (i - 1)) * 2;
	}
	ret += ((1LL << dgA) - 1) - A + 1;

	LL last = B & ((1LL << dgA) - 1);
	if (B - (1LL << (dgB - 1)) >= A) {
		ret += 1LL << dgA;
	}
	else {
		ret += solve(0, last);
		ret += ((1LL << dgA) - 1) - A + 1;
	}
	return ret;

}

int main()
{
	LL A, B;
	scanf("%lld %lld", &A, &B);
	LL ans = solve(A, B);
	printf("%lld\n", ans);
	return 0;
}