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: Wrong Answer)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long A = long.Parse(Console.ReadLine());
        long B = long.Parse(Console.ReadLine());
        int b;
        for(b=63;b>=0;b--){
            if(((((long)1 << b) & A) == 0) && ((((long)1 << b) & B) != 0)){
                long temp = A;
                A = B;
                B = temp;
                break;
            }
            else if(((((long)1 << b) & A) != 0) && ((((long)1 << b) & B) == 0)){
                break;
            }
            else if(((((long)1 << b) & A) != 0) && ((((long)1 << b) & B) != 0)){
                A -= (long)1 << b;
                B -= (long)1 << b;
            }
        }
        long count = ((long)1 << b) - B;
        int c;
        for(c = b-1;c >= 0;c--){
            if(((((long)1 << c) & A) != 0)){
                break;
            }
        }
        long C = ((long)1 << (c+1));
        count += Math.Min((long)1 << b,count + C);
        sb.Append(count+"\n");
    }
}