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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define fr first
#define sc second
#define pb push_back
#define mpr make_pair
#define ppb pop_back()
#define ins insert
#define sz(s) int(s.size())
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
ll f(ll l1, ll r1, ll l2, ll r2){
	if(l1 <= l2 && r2 <= r1)return r2 - l2 + 1;
	if(l1 <= l2)return r1 - l2 + 1;
	return r2 - l1 + 1;
}
ll st(ll a){
	ll lvl = 0;
	while((a / 2) > 0)a /= 2, ++lvl;
	return lvl;
}
ll rec(ll a, ll b){
	if(a == b)return 1ll;
	ll pw = 1, ans = 0, c = 0, x = 0, c1 = 0, c2 = 0, x2 = 0, pw2 = 0, sum = 0, lvl = 0, mul = 0;
	vector <ll> g;
	g.clear();
	while(pw * 2 - 1 < a)pw *= 2;
	while(pw <= b){
		g.pb(pw);
		pw *= 2;
	}
	if(a < 2)return pw - a;
//	cout << sz(g);
//	return 0;
	if(sz(g) > 2){
		for(auto to : g){
			ans += f(a, b, to, to * 2 - 1);
		}
		c = g[sz(g) - 1];
		x = b - c;
		ans -= x + 1;
//		return ans;
		lvl = 0;
		if(x) {
			pw = 1;
			while(pw * 2 <= x)pw *= 2, ++ lvl;
			ans += pw * 2;
			++lvl;
		}
		for(int i = sz(g) - 2;st(g[i]) >= lvl && i > 0; -- i)ans += g[i];
		if(st(g[1]) > lvl)ans += rec(a, g[1]) - f(a, b, g[0], g[0] * 2 - 1) - 1;
		else if(!x)++ans;
//		cout << ans;
		return ans;
	}
	if(sz(g) == 2){
		c1 = g[0];
		c2 = g[1];
		ans = f(a, b, c1, c1 * 2 - 1);
		x = b - c2;
		if(x > 0){
		pw = 1;
		while(pw * 2 <= x)pw *= 2;
		if(pw * 2 == c2){
			ans += c2;
//			cout << ans;
			return ans;
		}
		}
		else pw = 0;
		pw2 = 1, lvl = 0;
		while(pw2 * 2 <= a){
			pw2 *= 2;
			++lvl;
		}
		sum = c1;
//		lvl = 0;
		for(int i = lvl - 1; i >= 0 ;--i){
			lvl = -1;
			if((a >> i) % 2 == 1){
				sum += pow(2, i);
				lvl = i;
				break;
			}
		}
		if(lvl != -1){
		/*if(sum != a)++lvl;
		if(pow(2, lvl) / 2 <= pw){
			if(pow(2, lvl) == c1 / 2){
				ans += f(a, b, c1, c1 * 2 - 1);
				if(pw)ans += pw * 2;
				else ++ans;
				cout << ans;
				return ans;
			}/*
			if(lvl || pw){
			ans += c1;
			//cout << ans;
			return ans;

			}*/
		//}
//		if(lvl != -1){
		ans += f(a, b, c1, c1 * 2 - 1);
		if(pw)ans += pw * 2;
		else ++ans;
		return ans;
		}
		ans += c1;
		return ans;
	}
//	cout << "ok";
	return rec(a - g[0], b - g[0]);
}
ll a, b, ans;
bool u[10000];
int main()
{
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//srand(time(0));
	cin >> a >> b;
	cout << rec(a, b);
	return 0;
}