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 <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll calc(ll a,int i)
{
    ll s=1;
    while (i>=0)
    {
        if (!(a&(1ll<<i))) s+=1ll<<i;
        i--;
    }
    return s;
}

ll solve(ll a,ll b,int i)
{
    if (a<=b) return 1ll<<(i+1);
    if (b>=(1ll<<i)) return 1ll<<(i+1);
    if (!i) return 2;
    if (a<(1ll<<i)) return solve(a,b,i-1)+(1ll<<i);
    ll ans=0;
    for (int j=i-1;j>=-1;j--) if (j==-1||(b&(1ll<<j))) {ans+=(1ll<<(j+1));break;}
    return ((1ll<<(i+1))-a)+ans;
}

int main()
{
    //freopen("input.txt","r",stdin);
    ll a,b,ans=0;cin>>a>>b;
    if (a==b) {puts("1");return 0;}
    for (int i=59;i>=0;i--)
        if ((b&(1ll<<i))&&!(a&(1ll<<i)))
        {
            ans=calc(a&((1ll<<i)-1),i-1)+solve(a&((1ll<<i)-1),b&((1ll<<i)-1),i-1);
            break;
        }
    cout<<ans<<endl;
    return 0;
}