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 <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  _int64 i,j,a,b,tmp,ans,tmp1,cap,l1,r1;
  scanf("%lld%lld",&a,&b);
  ans=0;
  cap=(1LL<<62);
  for (i=60;i>=0;i--)
  {
    tmp=(1LL<<i);
    if ((a-1)/tmp<b/tmp)
    {
      tmp1=(b/tmp)*tmp;
      //cout<<a<<" "<<b<<" "<<tmp<<" "<<tmp1<<" "<<ans<<endl;
      if (b-a+1>=tmp)
      {
        ans+=tmp;
        ans+=tmp1-a;
        if (cap<tmp1+tmp)
        {
          ans-=tmp1+tmp-cap;
        }
        break;
      }
      else
      {
        ans+=(tmp1-a+1);
        if (tmp1-a>0)
        {
          l1=(a|tmp1);
          r1=tmp1+tmp-1;
          if (cap-1<r1) r1=cap-1;
          if (r1-l1+1>0)
            ans+=r1-l1+1;
        }
        cap=l1;
        a=tmp1+1;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}