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: Accepted)

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "bitset"

using namespace std;

//const long long int MOD = 998244353;
const long long int MOD = 1000000007;
const long double EPS = 1e-7;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> L >> R;
	if (L == R) {
		cout << 1 << endl;
		return 0;
	}
	N = L;
	M = R;
	while (N) {
		H++;
		N >>= 1;
	}
	H--;
	while (M) {
		W++;
		M >>= 1;
	}
	W--;
	while (H == W) {
		L -= 1LL << H;
		R -= 1LL << W;
		N = L;
		M = R;
		H = 0;
		W = 0;
		while (N) {
			H++;
			N >>= 1;
		}
		H--;
		while (M) {
			W++;
			M >>= 1;
		}
		W--;
	}
	//cout << L << " " << R << endl;
	//cout << (1LL << W) << endl;
	long long int l = L + (1LL << W);
	long long int r = (1LL << (W + 1)) - 1;
//	cout << l << " " << r << endl;
	long long int box = R;
	box -= (1LL << W);
	long long int bag = box;
	int num = 0;
	while (bag) {
		bag /= 2;
		num++;
	}
	//cout << (1LL << num) - 1+(1LL<<W) << endl;
	if (l <= (1LL << num) - 1 + (1LL << W)) {
		cout << (1LL << (W + 1)) - L << endl;
		return 0;
	}
	else {
		cout << r - l + 1 + (1LL << num) - 1 + (1LL << W) - L + 1 << endl;
	}
	return 0;
}