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<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  ll a, b; cin >> a >> b; int end=-1, begin;
  rep(i, 61){
    if(((1LL<<(60-i)) & a) && ((1LL<<(60-i)) & b)){
      a-=(ll)pow(2, 60-i); b-=(ll)pow(2, 60-i); continue;
    }
    else if(!((1LL<<(60-i)) & a) && !((1LL<<(60-i)) & b)){
      continue;
    }
    else break;
  }
  if(a==0 && b==0){
    cout << 1 << endl; return 0;
  }
  //cout << a << " " << b << endl;
  //rep(i, 61){
    //if((1LL<<(60-i)) & a) cout << 1;
    //else cout << 0;
  //}
  //cout << endl;
  //rep(i, 61){
    //if((1LL<<(60-i)) & b) cout << 1;
    //else cout << 0;
  //}
  //cout << endl;
  rep(i, 61){
    if((1LL<<(60-i)) & b){
      begin = 60-i;
      for(int j=begin-1; j>=0; j--){
        if((1LL<<j) & b){
          end = j; break;
        }
      }
      if(end!=-1) break;
    }
  }
  ll ans = 0;
  ans+=(ll) (pow(2, begin) + pow(2, end+1));
    ll tmp = a;
    rep(i, end+1){
      tmp/=2;
    }
   //cout << begin << " " << end << endl;
    //cout << tmp << endl;
    //cout << (ll)pow(2, begin-end-1)-tmp-1 << endl;
    //cout << begin << " " << end << endl;
    ans+=((ll)pow(2, begin-end-1)-tmp-1)*pow(2, end+1);
    //cout << end+1 << endl;
    if(tmp!=0){
      ll tmpb = 0;
      rep(i, end+1){
        if((1LL<<i) & a) tmpb+=(ll)pow(2, i);
      }
      //cout << begin << " " << end << endl;
      //rep(i, 61){
        //if((1LL<<(60-i)) & tmpb) cout << 1;
        //else cout << 0;
      //}
      //cout << endl;
      //cout << end+1 << endl;
      //cout << (ll)pow(2, end+1) << endl;
      ans+=(ll)pow(2, end+1) - tmpb;
    }
  ans-=a;
  cout << ans << endl;
}