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 <bits/stdc++.h>

using namespace std;

const long long MAX_BIT = 60;

long long a, b, ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    cin >> a >> b;

    long long mostBit = 0ll;
    for (long long bit = MAX_BIT; bit >= 0ll; bit--) {
        if ((a & (1ll << bit)) + (b & (1ll << bit)) != (1ll << bit)) {
            a = a & ~(1ll << bit);
            b = b & ~(1ll << bit);
        } else {
            mostBit = 1ll << bit;

            break;
        }
    }

    b = b & ~mostBit;

    long long mostBit2 = 0ll;
    for (long long bit = MAX_BIT; bit >= 0ll; bit--) {
        if ((b & (1ll << bit)) > 0) {
            mostBit2 = 1ll << bit;

            break;
        }
    }

//    for (int bit = 0; bit <= MAX_BIT; bit++) {
//        if ((a & (1ll << bit)) > 0) {
//            cerr << 1;
//        } else {
//            cerr << 0;
//        }
//    }
//
//    cerr << '\n';
//
//    for (int bit = 0; bit <= MAX_BIT; bit++) {
//        if ((b & (1ll << bit)) > 0) {
//            cerr << 1;
//        } else {
//            cerr << 0;
//        }
//    }
//
//    cerr << '\n';
//
//    cerr << mostBit << ' ' << mostBit2 << '\n';

    ans = (mostBit - a) + max(1ll, min(mostBit, (mostBit - a) + max(1ll, 2 * mostBit2)));

    cout << ans << endl;

    return 0;
}