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 Kotlin (1.0.0) (judge verdict: Accepted)

import java.util.*

fun exp(d: Int): Long {
    var ans: Long = 1
    for (i in 1..d-1) {
        ans *= 2
    }
    return ans
}


fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    var a = cin.nextLong()
    var b = cin.nextLong()
    var at: Long = a
    var bt: Long = b
    var ad: Int = 0
    var bd: Int = 0
    while (b > 0) {
        at = a
        bt = b
        ad = 0
        bd = 0
        while (bt > 0) {
            if (at > 0) {
                ad += 1
            }
            at = (at shr 1)
            bt = (bt shr 1)
            bd += 1
        }
        if (ad != bd) {
            break
        }
        val top = exp(ad)
        a = a - top
        b = b - top
    }
    if (b == 0.toLong()) {
        println(1)
    } else {
        val e = exp(bd)
        var non_top = b - e
        var non_top_d: Int = 0
        while (non_top > 0) {
            non_top = (non_top shr 1)
            non_top_d += 1
        }
        val temp = exp(non_top_d+1) - 1
        val under = e - a
        if (temp + under > e - 1) {
            println(e*2 - a)
        } else {
            println(e + temp - a + 1 + under)
        }
    }
}