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



Sample input:
7
9


Sample output:
4

Submission status: Wrong Answer

Solution code:
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 len(cbin)>1 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)

Submission status: Wrong Answer

Solution code:
a,b=int(input( )),int(input( ))
print(a+1)

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
a=int(a)
b=int(b)
print(a-b)

Submission status: Wrong Answer

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

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

t = a ^ b
n = len(bin(t)) - 2

T = 1 << (n - 1)

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

sb = b & (T - 1)
len_sb = len(bin(sb)) - 2
b_max = (2 ** len_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)

Submission status: Wrong Answer

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

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

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

t = a ^ b
n = bitlen(t)

T = 2**(n-1)

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

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

Submission status: Wrong Answer

Solution code:
a=bin(input()+(1<<61))[2:]
b=bin(input()+(1<<61))[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:
	result=result*2+1
else:
	b="1"*len(b)
	if int(b, 2)>=int(a, 2):
		result+=(1<<(len(a)-1))
	else:
		result=result*2+int(b, 2)+1
print result

Submission status: Wrong Answer

Solution code:
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:
	result=result*2+1
else:
	b="1"*len(b)
	if int(b, 2)>=int(a, 2):
		result+=(1<<(len(a)-1))
	else:
		result=result*2+int(b, 2)+1
print result

Submission status: Wrong Answer

Solution code:

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              # [A,2^t-1]
    r = t-1
    while 2**t + 2**r > B and r>=0:
        r-=1
    print(r)
    # [2^t,2^t+2^{r+1}-1] \cup [2^t+A,2^{t+1}-1]
    C = 2**(r+1)
    if C < A:
        ans += C + 2**t - A
    else:
        ans += 2**t
    print(ans)

Submission status: Wrong Answer

Solution code:
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
	print(t-a-(a-(1<<(k+1))*bool(a>(1<<(k+1)))))

Submission status: Wrong Answer

Solution code:
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
	print(t-a-(a-(1<<(k+1))*bool(a-(1<<(k+1)))))

Submission status: Wrong Answer

Solution code:
import math as mt



def diff(bita,bitb):
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1':
            break
    if 2 ** (length - x) - 1 < b:
        print((2 ** dega - b) + 2 ** (length - x) + 2 ** dega - b)
    else:
        print(2 ** (dega + 1) - b)

a = int(input())
b = int(input())
if b > a:
    a,b = b,a

dega = int(mt.log(a, 2))
degb = int(mt.log(b, 2))

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

if dega != degb:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    diff(bita, bitb)
else:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1' and bitb[x] == '0':
            break
    length = len(bita[x:])
    a = int(bita[x:], 2)
    b = int(bitb[x:], 2)
    dega = length - 1
    diff(bita[x:], bitb[x:])

Submission status: Wrong Answer

Solution code:
import math as mt



def diff(bita,bitb,x):
    if 2 ** (length - x) < b:
        print((2 ** dega - b) + 2 ** (length - x) + 2 ** dega - b)
    else:
        print(2 ** (dega + 1) - b)

a = int(input())
b = int(input())
if b > a:
    a,b = b,a

dega = int(mt.log(a, 2))
degb = int(mt.log(b, 2))

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

if dega != degb:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1':
            break
    diff(bita, bitb, x)
else:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1' and bitb[x] == '0':
            break
    print(2 ** dega + 2 ** (length - x) - b)

Submission status: Wrong Answer

Solution code:
import math as mt



def diff(bita,bitb,x):
    if 2 ** (length - x) < b:
        print((2 ** dega - b) + 2 ** (length - x) + 2 ** dega - b)
    else:
        print(2 ** (dega + 1) - b)

a = int(input())
b = int(input())
if b > a:
    a,b = b,a

dega = int(mt.log(a, 2))
degb = int(mt.log(b, 2))

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

if dega != degb:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1':
            break
    diff(bita, bitb, x)
else:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1' and bitb[x] == '0':
            break
    dega = len(bita) - 1
    diff(bita[x:], bitb[x:], 0)

Submission status: Wrong Answer

Solution code:
import math as mt



def diff(bita,bitb,x):
    if 2 ** (length - x) < b:
        print((2 ** dega - b) + 2 ** (length - x) + 2 ** dega - b)
    else:
        print(2 ** (dega + 1) - b)

a = int(input())
b = int(input())
if b > a:
    a,b = b,a

dega = int(mt.log(a, 2))
degb = int(mt.log(b, 2))

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

if dega != degb:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1':
            break
    diff(bita, bitb, x)
else:
    bita = "{0:b}".format(a)
    bitb = "{0:b}".format(b)
    length = len(bita)
    for x in range(1, length + 1):
        if x == length:
            break
        if bita[x] == '1' and bitb[x] == '0':
            break
    diff(bita[x:], bitb[x:], 0)

Submission status: Wrong Answer

Solution code:
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)
    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()

Submission status: Wrong Answer

Solution code:
import math as mt

a = int(input())
b = int(input())
if b > a:
    a,b = b,a

dega = int(mt.log(a,2))
degb = int(mt.log(b,2))
bita = "{0:b}".format(a)
bitb = "{0:b}".format(b)
length = len(bita)
if a==b:
    print(1)
    exit()
for x in range(1, length + 1):
    if x == length:
        break
    if bita[x] == '1':
        break
if dega != degb:
    if 2 ** (length - x) < b:
        print((2 ** (dega)-b) + int(2**(length - x)) + 2 ** dega - b)
    else:
        print(2 ** (dega + 1) - b)
else:
    print(2 ** dega + 2 ** (length - x) - b)

Submission status: Wrong Answer

Solution code:
import math as mt

a = int(input())
b = int(input())
if b > a:
    a,b = b,a

dega = int(mt.log(a,2))
degb = int(mt.log(b,2))
bita = "{0:b}".format(a)
bitb = "{0:b}".format(b)
length = len(bita)
if a==b:
    print(1)
    exit()
for x in range(1, length + 1):
    if x == length:
        break
    if bita[x] == '1':
        break
if dega != degb:
    if 2 ** (length - x) < b:
        print((2 ** (dega)-b) + int(2**(length - x - 1)) + 2 ** dega - b)
    else:
        print(2 ** (dega + 1) - b)
else:
    print(2 ** dega + 2 ** (length - x) - b)

Submission status: Wrong Answer

Solution code:
import math as mt

a = int(input())
b = int(input())
if b > a:
    a,b = b,a

dega = int(mt.log(a,2))
degb = int(mt.log(b,2))
bita = "{0:b}".format(a)
bitb = "{0:b}".format(b)
length = len(bita)
if a==b:
    print(1)
    exit()
for x in range(1, length + 1):
    if x == length:
        break
    if bita[x] == '1':
        break
if dega != degb:
    if 2 ** (length - x) < b:
        print((2 ** (dega)-b) + 2**(length - x) + 2 ** dega - b)
    else:
        print(2 ** (dega + 1) - b)
else:
    print(2 ** dega + 2 ** (length - x) - b)

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())

#A = int("111",2)
#B = int("1110",2)

binA = bin(A)[2:]
binB = bin(B)[2:]

#print("A: {0}\nB: {1}".format(A, B))
if A == B:
    print(1)

elif len(binB) - len(binA) > 1:
    maxnum = int("1" * len(binB), 2)
    print(maxnum - A + 1)

elif len(binB) - len(binA) == 1:
    res = 2 * (int("1" * len(binA), 2) - A + 1)
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == "0":
            continue
        else:
            res += 2 ** (len(binB) - i)
            break
    else:
        res += 1
    print(res)

else:
    same = ""
    for i in range(len(binA)):
        if binA[i] == binB[i]:
            same += binA[i]
        else:
            break
    same_num = len(same)
    #print("same_num", same_num)

    state = same + "0" * (len(binA) - same_num)
    #print("state", state)
    res = int(state, 2) - A
    #print("res(temp): {}".format(res))
    for i in range(len(binB) - same_num):
        #print("nowi: ", i)
        #print("B_i", binB[i + same_num])
        if binB[i + same_num] == "0":
            continue
        else:
            res += 2 ** (len(binB) - same_num  - i )
            break
    else:
        res += 1
    print(res)

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())
a = len(bin(A)) - 2
b = len(bin(B)) - 2
x = bin(A)[3:a+2]
y = bin(B)[3:b+2]
X = x.lstrip('0')
Y = y.lstrip('0')
lx = int(len(X))
ly = int(len(Y))

if a == b and lx != 0:
	print(pow(2, ly + 1) - pow(2, lx - 1) - A + 1)
elif a == b and lx == 0:
	print(pow(2, ly + 1) - pow(2, lx) - A +1)
elif a == b - 1:
	print(B - A * 2 + 1 + pow(2, a))
else:
	print(pow(2, b) - A - 1)

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())

#A = int("10001",2)
#B = int("11010",2)

binA = bin(A)[2:]
binB = bin(B)[2:]

#print("A: {0}\nB: {1}".format(A, B))
if A == B:
    print(1)

elif len(binB) - len(binA) > 1:
    maxnum = int("1" * len(binB), 2)
    print(maxnum - A + 1)

elif len(binB) - len(binA) == 1:
    res = 2 * (int("1" * len(binA), 2) - A + 1)
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == "0":
            continue
        else:
            res += 2 ** (len(binB) - i)
            break
    else:
        res += 1
    print(res)

else:
    same = ""
    for i in range(len(binA)):
        if binA[i] == binB[i]:
            same += binA[i]
        else:
            break
    same_num = len(same)
    #print("same_num", same_num)

    state = same + "0" * (len(binA) - same_num)
    #print("state", state)
    res = int(state, 2) - A
    #print("res(temp): {}".format(res))
    for i in range(len(binB) - same_num):
        #print("nowi: ", i)
        #print("B_i", binB[i + same_num])
        if binB[i + same_num] == "0":
            continue
        else:
            res += 2 ** (len(binB) - same_num  - i )
            break
    print(res)

Submission status: Wrong Answer

Solution code:
import sys
A = int(raw_input())
B = int(raw_input())
a_list = []
b_list = []
tmp = A
while tmp > 0:
  if tmp % 2 == 0:
    a_list.insert(0,0)
  else:
    a_list.insert(0,1)
  tmp /= 2
tmp = B
while tmp > 0:
  if tmp % 2 == 0:
    b_list.insert(0,0)
  else:
    b_list.insert(0,1)
  tmp /= 2
#print a_list
#print b_list
ans = 0
blen = len(b_list)
alen = len(a_list)
if A == B:
  print "1"
  sys.exit()
if blen - alen >= 2:
  ans += pow(2,alen) - A
  for i in range(blen-alen):
    ans += pow(2,alen+i)
  print ans
  sys.exit()

if blen - alen == 1:
  #ans += pow(2,alen) - A
  A+= pow(2,blen)
  B+= pow(2,blen)
  blen += 1
  alen = blen
  a_list=[]
  b_list=[]
  tmp = A
  while tmp > 0:
    if tmp % 2 == 0:
      a_list.insert(0,0)
    else:
      a_list.insert(0,1)
    tmp /= 2
  tmp = B
  while tmp > 0:
    if tmp % 2 == 0:
      b_list.insert(0,0)
    else:
      b_list.insert(0,1)
    tmp /= 2

pos = 0
A_ = A
B_ = B

for i in range(alen):
  if a_list[i] != b_list[i]:
    pos = i
    break
  if(a_list[i] == 1):
    A_ -= pow(2,alen-i-1)
    B_ -= pow(2,blen-i-1)
B_ -= pow(2,blen-pos-1)
a_list2 = []
b_list2 = []
tmp = A_
while tmp > 0:
  if tmp % 2 == 0:
    a_list2.insert(0,0)
  else:
    a_list2.insert(0,1)
  tmp /= 2
tmp = B_
while tmp > 0:
  if tmp % 2 == 0:
    b_list2.insert(0,0)
  else:
    b_list2.insert(0,1)
  tmp /= 2
ans += B - A + 1
if B_ > A_ or len(a_list2) == len(b_list2):
  ans += pow(2,alen-pos-1)-B_- 1
else:
  ans += pow(2,alen-pos-1)-A_
  ans += pow(2,len(b_list2)) -B_ - 1
print ans

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())
a = len(bin(A)) - 2
b = len(bin(B)) - 2
x = bin(A)[3:a+1]
y = bin(B)[3:b+1]
X = x.rstrip('0')
Y = y.rstrip('0')
lx = int(len(X))
ly = int(len(Y))

if a == b and lx != 0:
	print(pow(2, ly + 1) - pow(2, lx - 1))
elif a == b and lx == 0:
	print(pow(2, ly + 1))
elif a == b - 1:
	print(B - A * 2 + 1 + pow(2, a))
else:
	print(pow(2, b) - A - 1)

Submission status: Wrong Answer

Solution code:
import sys
A = int(raw_input())
B = int(raw_input())
a_list = []
b_list = []
tmp = A
while tmp > 0:
  if tmp % 2 == 0:
    a_list.insert(0,0)
  else:
    a_list.insert(0,1)
  tmp /= 2
tmp = B
while tmp > 0:
  if tmp % 2 == 0:
    b_list.insert(0,0)
  else:
    b_list.insert(0,1)
  tmp /= 2
#print a_list
#print b_list
ans = 0
blen = len(b_list)
alen = len(a_list)
if A == B:
  print "1"
  sys.exit()
if blen - alen >= 2:
  ans += pow(2,alen) - A
  for i in range(blen-alen):
    ans += pow(2,alen+i)
  print ans
  sys.exit()

if blen - alen == 1:
  #ans += pow(2,alen) - A
  A+= pow(2,blen)
  B+= pow(2,blen)
  blen += 1
  alen = blen
  a_list=[]
  b_list=[]
  tmp = A
  while tmp > 0:
    if tmp % 2 == 0:
      a_list.insert(0,0)
    else:
      a_list.insert(0,1)
    tmp /= 2
  tmp = B
  while tmp > 0:
    if tmp % 2 == 0:
      b_list.insert(0,0)
    else:
      b_list.insert(0,1)
    tmp /= 2

pos = 0
A_ = A
B_ = B
print a_list
print b_list

for i in range(alen):
  if a_list[i] != b_list[i]:
    pos = i
    break
  if(a_list[i] == 1):
    A_ -= pow(2,alen-i-1)
    B_ -= pow(2,blen-i-1)
B_ -= pow(2,blen-pos-1)
print pos
print A_
print B_
a_list2 = []
b_list2 = []
tmp = A_
while tmp > 0:
  if tmp % 2 == 0:
    a_list2.insert(0,0)
  else:
    a_list2.insert(0,1)
  tmp /= 2
tmp = B_
while tmp > 0:
  if tmp % 2 == 0:
    b_list2.insert(0,0)
  else:
    b_list2.insert(0,1)
  tmp /= 2
ans += B - A + 1
print a_list2
print b_list2
print ans
print A_
print B_
if B_ > A_ or len(a_list2) == len(b_list2):
  ans += pow(2,alen-pos-1)-B_- 1
else:
  print "a"
  ans += pow(2,alen-pos-1)-A_
  ans += pow(2,len(b_list2)) -B_ - 1
  print pow(2,alen-pos-1)
print ans

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())
a = len(bin(A)) - 2
b = len(bin(B)) - 2
x = bin(A)[3:a+1]
y = bin(B)[3:b+1]
X = x.rstrip('0')
Y = y.rstrip('0')
lx = int(len(X))
ly = int(len(Y))

if a == b and lx != 0:
	print(pow(2, ly + 1) - pow(2, lx - 1))
elif a == b and lx == 0:
	print(pow(2, ly + 1) - pow(2, lx))
elif a == b - 1:
	print(B - A * 2 + 1 + pow(2, a))
else:
	print(pow(2, b) - A - 1)

Submission status: Wrong Answer

Solution code:
import sys
A = int(raw_input())
B = int(raw_input())
a_list = []
b_list = []
tmp = A
while tmp > 0:
  if tmp % 2 == 0:
    a_list.insert(0,0)
  else:
    a_list.insert(0,1)
  tmp /= 2
tmp = B
while tmp > 0:
  if tmp % 2 == 0:
    b_list.insert(0,0)
  else:
    b_list.insert(0,1)
  tmp /= 2
#print a_list
#print b_list
ans = 0
blen = len(b_list)
alen = len(a_list)
if blen - alen >= 2:
  ans += pow(2,alen) - A
  for i in range(blen-alen):
    ans += pow(2,alen+i)
  print ans
  sys.exit()

if blen - alen == 1:
  #ans += pow(2,alen) - A
  A+= pow(2,blen)
  B+= pow(2,blen)
  blen += 1
  alen = blen
  a_list=[]
  b_list=[]
  tmp = A
  while tmp > 0:
    if tmp % 2 == 0:
      a_list.insert(0,0)
    else:
      a_list.insert(0,1)
    tmp /= 2
  tmp = B
  while tmp > 0:
    if tmp % 2 == 0:
      b_list.insert(0,0)
    else:
      b_list.insert(0,1)
    tmp /= 2

pos = 0
A_ = A
B_ = B

for i in range(alen):
  if a_list[i] != b_list[i]:
    pos = i
    break
  if(a_list[i] == 1):
    A_ -= pow(2,alen-i-1)
    B_ -= pow(2,blen-i-1)
B_ -= pow(2,blen-pos-1)
a_list2 = []
b_list2 = []
tmp = A_
while tmp > 0:
  if tmp % 2 == 0:
    a_list2.insert(0,0)
  else:
    a_list2.insert(0,1)
  tmp /= 2
tmp = B_
while tmp > 0:
  if tmp % 2 == 0:
    b_list2.insert(0,0)
  else:
    b_list2.insert(0,1)
  tmp /= 2
ans += B - A + 1
if B_ > A_ or len(a_list2) == len(b_list2):
  ans += pow(2,alen-pos-1)-B_- 1
else:
  ans += pow(2,alen-pos-1)-A_
  ans += pow(2,len(b_list2)) -B_ - 1
print ans

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())

binA = bin(A)[2:]
binB = bin(B)[2:]

#print("A: {0}\nB: {1}".format(A, B))
if A == B:
    print(1)

elif len(binB) - len(binA) > 1:
    maxnum = int("1" * len(binB), 2)
    print(maxnum - A + 1)

elif len(binB) - len(binA) == 1:
    res = 2 * (int("1" * len(binA), 2) - A + 1)
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == "0":
            continue
        else:
            res += 2 ** (len(binB) - i)
            break
    else:
        res += 1
    print(res)

else:
    same_num = 0
    for i in range(len(binA)):
        if binA[i] != binB[i]:
            same_num = i - 1
            break
    state = binA[0:same_num] + "0" * (len(binA) - same_num)
    #print(state)
    res = int(binA[0:same_num] + "0" * (len(binA) - same_num), 2) - A
    #print("res(temp): {}".format(res))
    for i in range(len(binB) - same_num - 1):
        #print("nowi: ",i)
        #print("B_i", binB[i + same_num + 1])
        if binB[i + same_num + 1] == "0":
            continue
        else:
            res += 2 ** (len(binB) - same_num - 1 - i )
            break
    print(res)

Submission status: Wrong Answer

Solution code:
import sys
A = int(raw_input())
B = int(raw_input())
a_list = []
b_list = []
tmp = A
while tmp > 0:
  if tmp % 2 == 0:
    a_list.insert(0,0)
  else:
    a_list.insert(0,1)
  tmp /= 2
tmp = B
while tmp > 0:
  if tmp % 2 == 0:
    b_list.insert(0,0)
  else:
    b_list.insert(0,1)
  tmp /= 2
#print a_list
#print b_list
ans = 0
blen = len(b_list)
alen = len(a_list)
if blen - alen >= 2:
  ans += pow(2,alen) - A
  for i in range(blen-alen):
    ans += pow(2,alen+i)
  print ans
  sys.exit()

if blen - alen == 1:
  #ans += pow(2,alen) - A
  A+= pow(2,blen)
  B+= pow(2,blen)
  blen += 1
  alen = blen
  a_list=[]
  b_list=[]
  tmp = A
  while tmp > 0:
    if tmp % 2 == 0:
      a_list.insert(0,0)
    else:
      a_list.insert(0,1)
    tmp /= 2
  tmp = B
  while tmp > 0:
    if tmp % 2 == 0:
      b_list.insert(0,0)
    else:
      b_list.insert(0,1)
    tmp /= 2

pos = 0
A_ = A
B_ = B

for i in range(alen):
  if a_list[i] != b_list[i]:
    pos = i
    break
  if(a_list[i] == 1):
    A_ -= pow(2,alen-i-1)
    B_ -= pow(2,blen-i-1)
B_ -= pow(2,blen-pos-1)
a_list2 = []
b_list2 = []
tmp = A_
while tmp > 0:
  if tmp % 2 == 0:
    a_list2.insert(0,0)
  else:
    a_list2.insert(0,1)
  tmp /= 2
tmp = B_
while tmp > 0:
  if tmp % 2 == 0:
    b_list2.insert(0,0)
  else:
    b_list2.insert(0,1)
  tmp /= 2
ans += B - A + 1
if B_ > A_ or len(a_list2) == len(b_list2):
  ans += pow(2,alen-pos-1)-B_- 1
else:
  ans += pow(2,alen-pos-1)-A_
  ans += pow(2,len(b_list2)) -B_ - 1
print ans

Submission status: Wrong Answer

Solution code:
A=int(input())
B=int(input())
S=[]
#一番きれいな数をさがす
n=len(format(A^B,"b"))
kirei=2**(n-1)
for i in range(A,B+1):
  S+=[i]
for i in range(len(S)):
  S+=[S[i]|kirei]
SET=set(S)
print(len(SET))

Submission status: Wrong Answer

Solution code:
import sys
A = int(raw_input())
B = int(raw_input())
a_list = []
b_list = []
tmp = A
while tmp > 0:
  if tmp % 2 == 0:
    a_list.insert(0,0)
  else:
    a_list.insert(0,1)
  tmp /= 2
tmp = B
while tmp > 0:
  if tmp % 2 == 0:
    b_list.insert(0,0)
  else:
    b_list.insert(0,1)
  tmp /= 2
#print a_list
#print b_list
ans = 0
blen = len(b_list)
alen = len(a_list)
if blen - alen >= 2:
  ans += pow(2,alen) - A
  for i in range(blen-alen):
    ans += pow(2,alen+i)
  print ans
  sys.exit()

if blen - alen == 1:
  #ans += pow(2,alen) - A
  A+= pow(2,blen)
  B+= pow(2,blen)
  blen += 1
  alen = blen
  a_list=[]
  b_list=[]
  tmp = A
  while tmp > 0:
    if tmp % 2 == 0:
      a_list.insert(0,0)
    else:
      a_list.insert(0,1)
    tmp /= 2
  tmp = B
  while tmp > 0:
    if tmp % 2 == 0:
      b_list.insert(0,0)
    else:
      b_list.insert(0,1)
    tmp /= 2

pos = 0
A_ = A
B_ = B

for i in range(alen):
  if a_list[i] != b_list[i]:
    pos = i
    break
  A_ -= pow(2,alen-i-1)
  B_ -= pow(2,blen-i-1)
B_ -= pow(2,blen-pos-1)
a_list2 = []
b_list2 = []
tmp = A_
while tmp > 0:
  if tmp % 2 == 0:
    a_list2.insert(0,0)
  else:
    a_list2.insert(0,1)
  tmp /= 2
tmp = B_
while tmp > 0:
  if tmp % 2 == 0:
    b_list2.insert(0,0)
  else:
    b_list2.insert(0,1)
  tmp /= 2
ans += B - A + 1
if B_ > A_ or len(a_list2) == len(b_list2):
  ans += pow(2,alen-pos-1)-B_- 1
else:
  #print "a"
  ans += pow(2,alen-pos-1)-A_
print ans

Submission status: Wrong Answer

Solution code:
A=int(input())
B=int(input())
S=[]
#一番きれいな数をさがす
n=len(format(A^B,"b"))
kirei=2**(n-1)
for i in range(A,B+1):
  S+=[i]
SET=set(S)
for i in range(len(S)):
  SET.add(S[i]|kirei)
print(len(SET))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import math


def main():
    a = int(input())
    b = int(input())
    if a == b:
        print(1)
        return

    # 作れる数字は、高々2**k - 1 (k: floor(log2(b))+1)

    da = math.floor(math.log2(a)) + 1
    db = math.floor(math.log2(b)) + 1
    sys.stderr.write("da: {} db: {}\n".format(da, db))

    if da == db:
        for i in range(da):
            pw = 2**(da - i - 1)
            if a >= pw:
                a -= pw
                b -= pw
                sys.stderr.write("a: {:b} b: {:b}\n".format(a, b))
            elif b >= pw:
                break
        if a > 0:
            da = math.floor(math.log2(a)) + 1
        else:
            da = 0
        db = math.floor(math.log2(b)) + 1
        sys.stderr.write("da: {} db: {}\n".format(da, db))

    if da == 0:
        print(b + 1)
        return

    # A: a .. (2**k')-1 [k': da - 1]
    total = 2**(db-1) - a
    sys.stderr.write("ta: {}\n".format(total))
    # B: 2**k' + ...
    # B1: 0 .. b
    tb1 = 1
    b_bin = "{:b}".format(b)
    for i in range(1, len(b_bin)):
        if int(b_bin[i]) == 1:
            tb1 = 2**(db - i)
            break
    sys.stderr.write("tb1: {}\n".format(tb1))
    # B2: a .. (11..1)
    tb2 = total
    sys.stderr.write("tb2: {}\n".format(tb2))
    tb = min(tb1 + tb2, 2**(db-1))
    sys.stderr.write("tb: {}\n".format(tb))
    total += tb
    print(total)


main()

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())
a = len(bin(A)) - 2
b = len(bin(B)) - 2

if a == b:
	print(pow(2, -(b - a + len(bin(A - pow(2, a - 1))) - len(bin(pow(2, b + 1) - B)))) - A)
elif a == b - 1:
	print(B - A * 2 + 1 + pow(2, a))
else:
	print(pow(2, b) - A - 1)

Submission status: Wrong Answer

Solution code:
import sys
A = int(raw_input())
B = int(raw_input())
a_list = []
b_list = []
tmp = A
while tmp > 0:
  if tmp % 2 == 0:
    a_list.insert(0,0)
  else:
    a_list.insert(0,1)
  tmp /= 2
tmp = B
while tmp > 0:
  if tmp % 2 == 0:
    b_list.insert(0,0)
  else:
    b_list.insert(0,1)
  tmp /= 2
#print a_list
#print b_list
ans = 0
blen = len(b_list)
alen = len(a_list)
if blen - alen >= 2:
  ans += pow(2,alen) - A
  for i in range(blen-alen):
    ans += pow(2,alen+i)
  print ans
  sys.exit()

if blen - alen == 1:
  #ans += pow(2,alen) - A
  A+= pow(2,blen)
  B+= pow(2,blen)
  blen += 1
  alen = blen
  a_list=[]
  b_list=[]
  tmp = A
  while tmp > 0:
    if tmp % 2 == 0:
      a_list.insert(0,0)
    else:
      a_list.insert(0,1)
    tmp /= 2
  tmp = B
  while tmp > 0:
    if tmp % 2 == 0:
      b_list.insert(0,0)
    else:
      b_list.insert(0,1)
    tmp /= 2

pos = 0
A_ = A
B_ = B
#print a_list
#print b_list

for i in range(alen):
  if a_list[i] == 0:
    pos = i
    break
  A_ -= pow(2,alen-i-1)
  B_ -= pow(2,blen-i-1)
B_ -= pow(2,blen-pos-1)
#print pos
#print A_
#print B_
a_list2 = []
b_list2 = []
tmp = A_
while tmp > 0:
  if tmp % 2 == 0:
    a_list2.insert(0,0)
  else:
    a_list2.insert(0,1)
  tmp /= 2
tmp = B_
while tmp > 0:
  if tmp % 2 == 0:
    b_list2.insert(0,0)
  else:
    b_list2.insert(0,1)
  tmp /= 2
ans += B - A + 1
#print a_list2
#print b_list2
#print ans
#print A_
#print B_
if B_ > A_ or len(a_list2) == len(b_list2):
  ans += pow(2,alen-pos-1)-B_- 1
else:
  #print "a"
  ans += pow(2,alen-pos-1)-A_
  #print pow(2,alen-pos-1)
print ans

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())

binA = bin(A)[2:]
binB = bin(B)[2:]

#print("A: {0}\nB: {1}".format(binA, binB))
if A == B:
    print(1)

elif len(binB) - len(binA) > 1:
    maxnum = int("1" * len(binB), 2)
    print(maxnum - A + 1)
elif len(binB) - len(binA) == 1:
    res = 2 * (int("1" * len(binA), 2) - A + 1)
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == "0":
            continue
        else:
            res += 2 ** (len(binB) - i)

            break
    else:
        res += 1
    print(res)

else:
    res = int("1" + "0" * (len(binA) - 1), 2) - A
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == 0:
            continue
        else:
            res += 2 ** (len(binB) - i)
            break
    print(res)

Submission status: Wrong Answer

Solution code:
A = int(input())
B = int(input())


binA = bin(A)[2:]
binB = bin(B)[2:]

#print("A: {0}\nB: {1}".format(binA, binB))

if len(binB) - len(binA) > 1:
    maxnum = int("1" * len(binB), 2)
    print(maxnum - A + 1)
elif len(binB) - len(binA) == 1:
    res = 2 * (int("1" * len(binA), 2) - A + 1)
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == "0":
            continue
        else:
            res += 2 ** (len(binB) - i)

            break
    else:
        res += 1
    print(res)

else:
    res = int("1" + "0" * (len(binA) - 1), 2) - A
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == 0:
            continue
        else:
            res += 2 ** (len(binB) - i)
            break
    print(res)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import math


def main():
    a = int(input())
    b = int(input())
    if a == b:
        print(1)
        return

    # 作れる数字は、高々2**k - 1 (k: floor(log2(b))+1)

    da = math.floor(math.log2(a)) + 1
    db = math.floor(math.log2(b)) + 1
    sys.stderr.write("da: {} db: {}\n".format(da, db))

    if da == db:
        for i in range(da):
            pw = 2**(da - i - 1)
            if a >= pw:
                a -= pw
                b -= pw
            else:
                break
        da = math.floor(math.log2(a)) + 1
        db = math.floor(math.log2(b)) + 1
        sys.stderr.write("da: {} db: {}\n".format(da, db))

    # A: a .. (2**k')-1 [k': da - 1]
    total = 2**(db-1) - a
    sys.stderr.write("ta: {}\n".format(total))
    # B: 2**k' + ...
    # B1: 0 .. b
    tb1 = 1
    b_bin = "{:b}".format(b)
    for i in range(1, len(b_bin)):
        if int(b_bin[i]) == 1:
            tb1 = 2**(db - i)
            break
    sys.stderr.write("tb1: {}\n".format(tb1))
    # B2: a .. (11..1)
    tb2 = total
    sys.stderr.write("tb2: {}\n".format(tb2))
    tb = min(tb1 + tb2, 2**(db-1))
    sys.stderr.write("tb: {}\n".format(tb))
    total += tb
    print(total)


main()

Submission status: Wrong Answer

Solution code:
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)
    res = t - l
    if h - t >= l:
        res += t
    else:
        res += res + f(0, h - t, i - 1)
    return res
print f(a, b, 60)

Submission status: Wrong Answer

Solution code:
# D
res = 0

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

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


while True:
    # find log2A and log2B
    C = pow2_floor_log2(B)
    if A < C:
        # A to 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)

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

def can_make(A,B):
    # [A,B] の元のorで、{B} 以外の方法でBを作れるかどうか。たいていTrue
    if A == B:
        return False
    if B%2 == 0:
        return can_make((A+1)//2,B//2)
    # Bが奇数なら、{B-1,B}が満たす
    return True

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:
        # 上位の桁では基本的にはA//2～B//2が使える。
        # ただし、{B} 以外でないといけない
        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)

Submission status: Time Limit Exceeded

Solution code:
A=int(input())
B=int(input())
S=[]
times=len(format(A^B,"b"))
for i in range(A,B+1):
  S+=[i]
SET=set(S)
for i in range(len(S)):
  for j in range(i,len(S)):
    SET.add(S[i]|S[j])
print(len(SET))