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 Ruby (2.3.3) (judge verdict: Wrong Answer)

def solve(a, b)
  r = 60
  until r==0
    break unless a[r]==b[r]
    a ^= (1<<r) if a[r]==1
    b ^= (1<<r) if b[r]==1
    r -= 1
  end
  return (a!=b) ? 1 : 0 if r==0
  sum = 2**r - a
  if b==2**r
    sum += 2**r - a
    sum += 1 if a==0
  else
    k = r-1
    k -= 1 until b[k]==1
    if a <= 2**(k+1)
      sum += 2**r
    else
      sum += 2**(k+1)
      sum += 2**r - a
    end
  end
  sum
end

p solve(gets.to_i, gets.to_i)