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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long naive(long long A, long long B) {
    set<long long> se;
    for (long long bit = 0; bit < 1LL<<(B-A+1); ++bit) {
        long long val = 0;
        for (long long v = 0; v < B-A+1; ++v) {
            if (bit & (1LL<<v)) val |= A+v;
        }
        if (val) se.insert(val);
    }
    return se.size();
}


const int MAX = 60;

long long count(long long A, int size) {
    long long all = 1LL<<size;
    for (int i = 0; i < size; ++i) if (A & (1LL<<i)) all -= 1LL<<i;
    return all;
}

long long count(long long A, int size, int masksize) {
    long long all = 1LL<<size;
    long long res = all;
    int maxsize = 0;
    for (int i = 0; i < size; ++i) if (A & (1LL<<i)) maxsize = i+1, res -= 1LL<<i;

    //COUT(maxsize); COUT(all); COUT(res);
    
    if (masksize >= maxsize) return all;
    else return res + (1LL<<masksize);
}

long long solve(long long A, long long B) {
    if (A == B) return 1;
    int size = -1;
    for (int i = 0; i < MAX; ++i) if ( !(A & (1LL<<i)) && (B & (1LL<<i)) ) size = i;
    int bsize = 0;
    for (int i = 0; i < size; ++i) if (B & (1LL<<i)) bsize = i + 1;

    // size 桁が 0 の場合
    long long zero = count(A, size);
    
    // size 桁が 1 の場合
    long long one = count(A, size, bsize);

    
    //COUT(size); COUT(bsize); COUT(A); COUT(B); COUT(zero); COUT(one);
    
    return zero + one;
}

int main() {
    /*
    for (long long bet = 0; bet <= 15; ++bet) {
        for (long long a = 1; a <= 30; ++a) {
            cout << a << ", " << a+bet << ": " << naive(a, a+bet) << ", " << solve(a, a+bet) << endl;
        }
    }
    */
    
    long long A, B;
    while (cin >> A >> B) {
        cout << solve(A, B) << endl;
    }

}