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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;

fn main() {
    let mut a: i64 = read();
    let mut b: i64 = read();
    if a == b {
        println!("{}", 1);
        return;
    }
    let mut a2: Vec<i64> = vec![0; 61];
    let mut b2: Vec<i64> = vec![0; 61];
    let mut index = 0;
    while a > 0 {
        a2[60 - index] = a % 2;
        a /= 2;
        index += 1;
    }
    index = 0;
    while b > 0 {
        b2[60 - index] = b % 2;
        b /= 2;
        index += 1;
    }
    let mut r = 60;
    for i in 0..61 {
        if a2[i] != b2[i] {
            r = i;
            break;
        }
    }
    let mut a = 0;
    for i in r..61 {
        a *= 2;
        a += a2[i];
    }
    let po1 = 2_i64.pow(60 - r as u32) - 1;
    let mut ans = (po1 - a + 1) * 2;
    let mut flag = false;
    let mut po2 = 0;
    for i in r + 1..61 {
        if b2[i] == 1 {
            flag = true;
        }
        po2 *= 2;
        po2 += if flag { 1 } else { b2[i] };
    }
    po2 += 2_i64.pow(60 - r as u32);
    let b = 2_i64.pow(60 - r as u32);
    let c = a + 2_i64.pow(60 - r as u32);
    ans += po2 - b + 1;
    if c <= po2 {
        ans -= (po2 - c) + 1;
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}