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::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;
use std::usize;
use std::cmp;
use std::collections::vec_deque::VecDeque;
use std::i64::MAX;

fn main() {
    let mut sc = Scanner::new();
    let a = sc.parse::<i64>();
    let b = sc.parse::<i64>();
    if a == b {
        print!("{}", 1);
        return;
    }

    let mut r = 0;
    for i in (0..61).rev() {
        if (a & (1 << i)) != (b & (1 << i)) {
            r = i;
            break;
        }
    }

    let c = (1 << r);

    let mut k = 0;
    for i in (0..r).rev() {
        if (b & (1 << i)) != 0 {
            k = i + 1;
            break;
        }
    }

    let d = c + (1 << k);
    let e = 2 * c;
    let f = (a & (c - 1));
    // [f, d), [f+c, e)


    if d >= f + c {
        // [f, e)
        println!("{}", e - f);
    } else {
        println!("{}", d - f + e - (f + c));
    }
}

struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }
}