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

use std::io;
use std::cmp::max;
use std::collections::VecDeque;

fn main() {
    let mut input = Input::new();
    let mut a: i64 = input.next().parse::<i64>().unwrap();
    let mut b: i64 = input.next().parse::<i64>().unwrap();
    if a == b {
        println!(1);
        return;
    }
    let c: i64 = a ^ b;
    let r: i64 = (0..64).filter(|x| ((1i64 << x) & c) > 0).max().unwrap();
    a &= (2i64 << r) - 1;
    b &= (2i64 << r) - 1;
    let k = (0..64)
        .filter(|x| ((1i64 << x) & b) > 0i64 && (2i64 << x) <= b)
        .max();
    let t = 1i64 << r;
    let s1 = a;
    let l1 = t;
    let s3 = t + a;
    let l3 = t * 2;
    let mut x: i64 = l1 - s1 + l3 - s3;
    if k.is_some() {
        let s2 = t;
        let l2 = t + (2i64 << k.unwrap());
        x += l2 - s2 - max(l2 - s3, 0);
    }
    println!("{}", x);
}

struct Input {
    queue: VecDeque<String>,
}

impl Input {
    fn new() -> Input {
        Input { queue: VecDeque::new() }
    }

    fn next(&mut self) -> String {
        if self.queue.is_empty() {
            let mut line = String::new();
            let _ = io::stdin().read_line(&mut line);
            for x in line.split_whitespace() {
                self.queue.push_back(String::from(x));
            }
        }
        return self.queue.pop_front().unwrap();
    }
}