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 <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

ull powULL(ull base, unsigned exp) {
  if (exp == 0)
    return 1;
  else if (exp % 2 == 0)
    return powULL(base * base, exp / 2);
  else
    return base * powULL(base, exp - 1);
}

int nlz(ull a) {
  int i = 64;
  while (a > 0) {
    i--;
    a >>= 1;
  }
  return i;
}

ull dp(ull a, ull b) {
  int i = 0, j = 0;

  i = 63 - nlz(a);
  j = 63 - nlz(b);

  if (a == 0) return powULL(2, j + 1);

  ull tmp1 = powULL(2, j);
  int k = 63 - nlz(b-tmp1);
  ull tmp2 = powULL(2, k+1);
  if (i == j)
    return dp(a - tmp1, b - tmp1);
  else if (a >= tmp2)
    return 2*tmp1 + tmp2 - 2 * a;
  else
    return 2 * tmp1 - a;
}

int main(int argc, char *argv[]) {
  ull A, B;

  cin >> A >> B;
  cout << dp(A, B) << endl;
  return 0;
}