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;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;
using ull = unsigned long long;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ull a, b; cin >> a >> b;
	if (a == b) {
		cout << 1 << endl;
		return 0;
	}

	vl x(64), y(64);
	REP(i, 64) {
		x[i] = (a >> i) & 1;
		y[i] = (b >> i) & 1;
	}

	ull ma_idx; // ビットが変わった点
	for (ll i = 63; i >= 0; --i) if (x[i] != y[i]) {
		ma_idx = i;
		break;
	}

	ll y_ma1 = -1;
	REP(i, ma_idx) if (y[i] == 1) {
		y_ma1 = i;
	}

	ull x_res0 = 0;
	REP(i, ma_idx) if (x[i] == 1) {
		x_res0 = i + 1;
	}

	ull ans = 0;

	ull y_freelen = y_ma1 + 1;
	ull x_freelen = ma_idx - x_res0;
	ull under = a & ((1ull << x_res0) - 1);
	ull diff = x_res0 == 0 ? 0 : (1ull << x_res0) - under;
	ull diff2 = (1ull << (x_res0 - y_freelen)) - (under >> y_freelen);
	if (y_freelen + x_freelen >= ma_idx) {
		ans += 1ull << ma_idx;
	} else {
		ans += (1ull << (y_freelen + x_freelen)) * diff2 + (1ull << x_freelen) * diff;
	}

	ans += 1ull << ma_idx;
	ans -= under;

	cout << ans << endl;
	return 0;
}