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 (Python):
def solve(a, b):
    if a == b:
        return 1

    f = 1 << 60
    r = 0
    while f:
        if r == 0 and b & f and a & f == 0:
            r = f
        elif r > 0 and b & f:
            k = f << 1
            break
        f >>= 1
    else:
        k = 1

    a &= r - 1

    if k > a:
        return (r << 1) - a

    return 2 * (r - a) + k


a = int(input())
b = int(input())
print(solve(a, b))

Solution (Python):
import sys
readline = sys.stdin.readline

def calc(A, B):
    if A == B:
        return 1
    for i in range(61, -1, -1):
        if A&(1<<i) and B&(1<<i):
            A ^= 1<<i
            B ^= 1<<i
        if not A&(1<<i) and B&(1<<i):
            break
    
    Bd = B ^ (1<<(B.bit_length())-1)
    BM = ((1<<Bd.bit_length())-1)
    B = B | BM
    C = (1<<(B.bit_length())-1)
    
    res = (B-A+1) + (C-max(BM+1, A))
    return res
A = int(readline())
B = int(readline())
print(calc(A, B))

Solution (Python):
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while len(abin)>1 and abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin and cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))-1
a=int(abin,2)
b=int(bbin,2)
lb=len(bbin)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**lb-a)
else:
  print(2**(lb-1)-a+lbnd-a+1)

Solution (Python):
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from functools import lru_cache

A = int(readline())
B = int(readline())

@lru_cache(None)
def can_make(A,B):
    
    if A == B:
        return False
    if B%2 == 0:
        return can_make((A+1)//2,B//2)
    
    return True

@lru_cache(None)
def F(A,B):
    if A==B:
        return 1
    
    ev = F((A+1)//2,B//2)
    
    if A%2==0:
        A += 1
    if B%2 == 1:
        od = F(A//2,B//2)
    else:
        
        
        od = F(A//2,B//2)
        if not can_make(A//2,B//2):
            od -= 1
    return ev + od

answer = F(A,B)
print(answer)

Solution (Python):
a = int(input())
b = int(input())

if a == b:
    print(1)
    exit()



def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

t = a ^ b
n = bitlen(t)

T = 1 << (n - 1)

a = a & (T * 2 - 1)
b = b & (T * 2 - 1)

sb = b & (T - 1)
b_max = (2 ** bitlen(sb) - 1) | T

if (T + a) > b_max:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)

Solution (Python):
a=bin(input()+(1<<60))[2:]
b=bin(input()+(1<<60))[2:]
if a==b:
	print 1
	exit()
while a[0]==b[0]:
	a=a[1:]
	b=b[1:]
assert a[0]=="0" and b[0]=="1"
result=int("1"+"0"*(len(a)-1), 2)-int(a, 2)
b=b[1:]
while b and b[0]=="0":
	b=b[1:]
if not b:
	b=0
else:
	b=(1<<len(b))-1
if b>=int(a, 2):
	result+=(1<<(len(a)-1))
else:
	result=result*2+b+1
print result

Solution (Python):
l = int(raw_input())
r = int(raw_input())
if l == r:
	print 1
	exit(0)
k = l ^ r
while k != (k & -k):
	k ^= k & -k
l &= (k << 1) - 1
r &= k - 1
while r != (r & -r):
	r ^= r & -r
r = r * 2 - 1 if r else 0
print 2 * k - l if r >= l else (k - l << 1) + r + 1

Solution (Python):

import math
A = int(input())
B = int(input())
if B < A: A,B = B,A

if A == B:
    print(1)
else:
    t = int(math.floor(math.log2(B)))
    while (A & 2**t) == (B & 2**t):
        if A & 2**t:
            A -= 2**t
            B -= 2**t
        t-=1
    ans = 2**t - A              
    r = t-1
    while 2**t + 2**r > B and r>=0:
        r-=1
    
    C = 2**(r+1)
    if C < A:
        ans += C + 2**t - A
    else:
        ans += 2**t
    print(ans)

Solution (Python):
a,b=int(input()),int(input())
if a==b:
	print(1)
else:
	r=60
	while (a&(1<<r))==(b&(1<<r)):
		r-=1
	t=(1<<(r+1))
	a&=t-1
	b&=t-1
	k=r-1
	while k>=0 and (b&(1<<k))==0:
		k-=1
	ans=t-a
	if a>(1<<(k+1)):
		ans-=a-(1<<(k+1))
	print(ans)

Solution (Python):
import fileinput

iterator = fileinput.input()

a = int(iterator.next())
b = int(iterator.next())

def compute(a, b):
    if a == b:
        return 1

    
    n = (a ^ b).bit_length()
    high_order_bit = 1 << (n-1)
    ones_mask = (high_order_bit << 1) - 1
    a = a & ones_mask
    b = b & ones_mask

    
    
    prefix_0_count = high_order_bit - a
    
    b_max = (1 << (b ^ high_order_bit).bit_length()) - 1
    if a > b_max:
        prefix_1_count = b_max + 1 + prefix_0_count
    else:
        prefix_1_count = high_order_bit

    return prefix_0_count + prefix_1_count

print compute(a, b)

Solution (Python):
import sys

def solve():
    a = int(input())
    b = int(input())

    if a == b:
        print(1)
        return

    t = a ^ b
    N = bitlen(t)

    a = a & (2**N - 1)
    b = b & (2**N - 1)

    blen = bitlen(b)

    sb = b & (2**(blen - 1) - 1)

    sblen = bitlen(sb)

    s = 2**sblen - 1

    ymax = b | s

    T = 2**(N - 1)

    ans = T - a

    if ymax < T + a:
        ans += ymax + 1 - a
    else:
        ans += T

    print(ans)

def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

if __name__ == '__main__':
    solve()

Solution (Python):
import sys

def solve():
    a = int(input())
    b = int(input())

    if a == b:
        print(1)
        return

    t = a ^ b
    N = len(bin(t)) - 2
    t = 1 << N

    a = a & (t - 1)
    b = b & (t - 1)

    blen = len(bin(b)) - 2

    sb = b & (2**(blen - 1) - 1)

    if sb == 0:
        sblen = 0
    else:
        sblen = len(bin(sb)) - 2

    s = (1<<sblen) - 1

    ymax = b | s

    T = 1<<(N - 1)

    ans = T - a

    if ymax < T + a:
        ans += ymax - T + 1 + T - a
    else:
        ans += T

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
a = int(raw_input())
b = int(raw_input())
def f(l, h, i):
    if i == 0:
        return h - l + 1
    t = (1 << i)
    if h < t:
        return f(l, h, i - 1)
    if l >= t:
        return f(l - t, h - t, i - 1)
    k = f(0, h - t, i - 1)
    if k >= l:
        return t - l + t
    else:
        return (t - l) * 2 + k
    return res
print f(a, b, 60)

Solution (Python):

res = 0

A = int(input())
B = int(input())

def pow2_floor_log2(x):
    res = 1
    while res*2 <= x:
        res *= 2
    return res

if A == B:
    res += 1
    
while A < B:
    
    C = pow2_floor_log2(B)
    if A < C:
        
        res += C - A
        if B > C:
            B_ = C + pow2_floor_log2(B - C)*2 - 1
        else:
            B_ = C
        if C + A <= B_:
            res += C
            break
        else:
            res += (C - A) + (B_ - C + 1)
            break
    else:
        A -= C
        B -= C

print(res)