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> ii;

#define X first
#define Y second

const int N=2e3+10;


ll solve(ll L,ll R){
    int st=61;
    if (L==R) return 1;
    while (st>=0&&((L&(1LL<<st))==(R&(1LL<<st)))) st--;
    int p1=st-1,p2=st-1;
    while (p1>=0&&!(L&(1LL<<p1))) p1--;
    if (p1==-1) return 1LL<<(st+1);
    while (p2>=0&&!(R&(1LL<<p2))) p2--;
//    cout<<st<<" "<<p1<<" "<<p2<<'\n';
    if (p2==-1) return (R-L)*2+1;
    if (p1<=p2) return ((1LL<<(st+2))-L);
    int len=st-p1-1+p2+1;
    /// < (1<<st)
    ll ans=(1LL<<st)-L;
    ///>= (1<<st)
    ans+=(1LL<<len)+(1LL<<(p1+1))*((1LL<<(st-p1-1))-1);
    ans+=(1LL<<(p1+1))-(L&((1LL<<(p1+1))-1));
    return ans;
}
int main(){
    ll L,R;
    cin>>L>>R;
    cout<<solve(L,R);
}