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::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn naive(a: usize, b: usize) -> u64 {
    println!("{:b}", a);
    println!("{:b}", b);
    let up = |mut x: usize|  {
        let mut res = 0;
        while x != 0 {
            res += 1;
            x >>= 1;
        }
        res
    };
    let mut dp = vec![false; 1<<up(b)];
    dp[a] = true;
    // debug!(dp);
    for num in a+1..b+1 {
        // debug!(num);
        let mut nex = dp.clone();
        nex[num] = true;
        for mask in 0..dp.len() {
            nex[mask|num] = nex[mask|num]||dp[mask];
        }
        dp = nex;
    }
    let a = dp.iter().fold(0, |sum, &x| {
        if x {
            sum + 1
        } else {
            sum
        }
    });
    // debug!(dp);
    a
}

fn solve(mut a: usize, mut b: usize) -> u64 {
    const MAX: usize = 61;
    for i in (0..MAX).rev() {
        if ((a>>i)&1) == ((b>>i)&1) {
            a = (!(1<<i))&a;
            b = (!(1<<i))&b;
        } else {
            break;
        }
    }
    if a == b {
        return 1;
    }
    let blen = {
        let mut b = b;
        let mut cnt = 0;
        while b != 0 {
            cnt += 1;
            b >>= 1;
        }
        cnt-1
    };
    // debug!(a); debug!(b);
    let mut res = ((1<<blen)-a)*2;
    debug!((1<<blen)-a);
    let to = {
        let mut s = false;
        let mut res = None;
        for i in (0..MAX).rev() {
            if (b>>i)&1 == 1 {
                // debug!(i);
                if !s {
                    s = true;
                } else {
                    res = Some(i);
                    break;
                }
            }
        }
        res
    };
    // debug!(to);
    if let Some(to) = to {
        let add = (1<<to+1);
        // debug!(add);
        res += add;
        res -= std::cmp::max(0, (add as i64 - 1 - a as i64 + 1)) as usize;
        if a == 0 {

        }
    }
    // res += 1;
    res as u64
}

fn main() {
    let a = readl!(usize);
    let b = readl!(usize);
    // println!("{}", naive(a, b));
    println!("{}", solve(a, b));
}