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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;

public class CSharp{
    public static void Main(){
        Kyopuro chokudai = new Kyopuro();
	    chokudai.AtCoder();
	}
}

public class Kyopuro{
    public void AtCoder(){
        long[] p = new long[62];
        p[0] = 1;
        for(int i=1; i<62; i++) p[i] = p[i-1] * 2;
        long a = long.Parse(Console.ReadLine());
        long b = long.Parse(Console.ReadLine());
        if(a == b) {
            Console.WriteLine(1);
            return;
        }
        long la = 0; long lb = 0;
        int ia = 0; while(p[ia] <= a) ia++;
        int ib = 0; while(p[ib] <= b) ib++;
        la = p[--ia];
        lb = p[--ib];
        while(la == lb){
            if(a == la) break;
            a -= la;
            b -= lb;
            while(p[ia] > a) ia--;
            while(p[ib] > b) ib--;
            la = p[ia]; lb = p[ib];
        }
        long c = b - lb;
        long lc = 0;
        if(c != 0){
            lc = (long)Math.Pow(2,1+(long)Math.Log(c, 2)) - 1;
        }
        Console.WriteLine(lb-a+1+Math.Min(lc + lb - a, lb-1));
    }
    
    public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
}