Problem:
 Score : 400 points    Problem Statement Let f(A, B) be the exclusive OR of A, A+1, ..., B . Find f(A, B) .   What is exclusive OR?  The bitwise exclusive OR of integers c_1, c_2, ..., c_n (let us call it y ) is defined as follows:   When y is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if, the number of integers among c_1, c_2, ...c_m whose binary representations have 1 in the 2^k 's place, is odd, and 0 if that count is even.   For example, the exclusive OR of 3 and 5 is 6 . (When written in base two: the exclusive OR of 011 and 101 is 110 .)

Solution (Python):


if __name__ == '__main__':
    A, B = map(int ,input().split(" "))
    if A % 2 == 0:
        if B % 2 == 1:
            t = (B-A+1)//2
            print(t%2)
        else:
            t = (B-A)//2
            print((t%2)^B)
    else:
        if B % 2 == 1:
            t = (B-A)//2
            print((t%2)^A)
        else:
            t = (B-A-1)//2
            print((t%2)^A^B)

Solution (Python):
a,b=[int(i) for i in input().split()]

bin_b = bin(b)[2:]
bit_len = len(bin_b)
bin_a = bin(a)[2:].zfill(bit_len)

ans_bit = []

a_odd = a + (1 - a%2)
odd_num = (b-a_odd)//2 + 1
if odd_num % 2 == 0:
  ans_bit.append('0')
else:
  ans_bit.append('1')

for i in range(1,bit_len):
  keta = bit_len - i - 1
  amari_a = 0
  if bin_a[keta] == '1':
    amari_a = 2**i - a % 2**i
  amari_b = 0
  if bin_b[keta] == '1':
    amari_b = b % 2**i + 1
  
  no_change = amari_a + amari_b
  if no_change % 2 == 0:
    ans_bit.append('0')
  else:
    ans_bit.append('1')
ans = ''.join(ans_bit[::-1])
ans = int(ans,2)

print(ans)

Solution (Python):
A, B = list(map(int, input().split()))
a = A % 2
b = B % 2

if not a and not b:
    num = [(B-A)//2%2, B]
elif a and b:
    num = [(B-A)//2%2, A]
elif not a and b:
    num = [(B-A+1)//2%2]
else:
    num = [(B-1-A)//2%2, A, B]

for n in num[1:]:
    num[0] ^= n
print(num[0])

Solution (Python):
def count(i, d):
    return int(i // d * (d / 2)) + max(int(i % d + 1 - d / 2), 0)


a, b = map(int, input().split(' '))

l = ['0' for i in range(40)]

for i in range(40):
    bb = count(b, 2**(i + 1))
    aa = count(a - 1, 2**(i + 1))
    if (bb - aa) % 2 == 0:
        l[i] = '0'
    else:
        l[i] = '1'
l.reverse()
print(int(''.join(l), 2))

Solution (Python):
A, B = list(map(int, input().split()))

def calc_num(N):
  if N==0:
    return 0
  if N % 4 == 1:
    return 1
  if N % 4 == 2:
    return N ^ 1
  if N % 4 == 3:
    return 0
  return N ^ 0

A = calc_num(A-1)
B = calc_num(B)

print(A^B)

Solution (Python):
a, b = map(int, input().split())


def mod(n):
    return n % 4


def xor(num):
    if mod(num-1) == 0:
        return 0
    elif mod(num-1) == 1:
        return num
    elif mod(num-1) == 2:
        return 1
    elif mod(num-1) == 3:
        return num + 1


print(xor(a-1) ^ xor(b))

Solution (Python):
A,B=map(int,input().split())
A-=1
if A%4==1:
    A=1
elif A%4==2:
    A+=1
elif A%4==3:
    A=0
if B%4==1:
    B=1
elif B%4==2:
    B+=1
elif B%4==3:
    B=0
print(A^B)

Solution (Python):
A, B = map(int, input().split())


def f(a):
    if a % 2 == 0:
        return 0^a if (a // 2) % 2 == 0 else 1^a
    else:
        return 0 if ((a+1) // 2) % 2 == 0 else 1

print(f(B)^f(A-1))

Solution (Python):
A, B = map(int, input().split())
def xor_upto(n):
    ans = 0
    if n%2 == 0:
        ans = n
    if ((n+1)//2)%2 == 1:
        ans = ans^1
    return ans
print(xor_upto(A-1)^xor_upto(B))

Solution (Python):
import numpy as np


def element_conn(l):
	result = ''
	for x in l:
		result += str(x)
	return result

def exclusive_or(n, m):
	array_bin_n = np.array(list(format(n, 'b')))
	array_bin_m = np.array(list(format(m, 'b')))
	num_elem_n = len(array_bin_n)
	num_elem_m = len(array_bin_m)
	
	if num_elem_m-num_elem_n > 0:
		array_zero = np.array(['0' for i in range(num_elem_m-num_elem_n)])
		array_added_bin_n = np.hstack((array_zero, array_bin_n))
		result = array_bin_m.astype(int) + array_added_bin_n.astype(int)
	else:
		result = array_bin_m.astype(int) + array_bin_n.astype(int)
	
	result[result==2]=0
	
	convert_list = list(result)
	
	final_result = int(element_conn(convert_list), 2)
	
	return final_result




A, B = map(int, input().split())

list_binary = []

if A%2 == 0:
	if B%2 == 0:
		if ((A+B)/2)%2 == 0:
			print(B)
		else:
			print(B+1)
	else:
		if ((A+B+1)/2)%2 == 0:
			print(0)
		else:
			print(1)
else:
	if B%2 == 0:
		if ((A+B-1)/2)%2 == 0:
			print(exclusive_or(A-1, B))
		else:
			print(exclusive_or(A, B))
	else:
		if ((A+B)/2)%2 == 0:
			print(A-1)
		else:
			print(A)

Solution (Python):
A, B = list(map(int, input().split()))

def xorsum(m):
  if m==3:
    return 0
  if m==2:
    return 3
  if m==1:
    return 1
  if m==0:
    return 0
  if m==-1:
    return 0
  h=1
  while h<=m:
    h=h*2
  h=h//2
  return xorsum(m-h)^(((m-h+1)%2)*h)

print(xorsum(B)^xorsum(A-1))

Solution (Python):
import io, sys, atexit, os

import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


def li ():
	return list (map (int, input ().split ()))


def num ():
	return map (int, input ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


mm = 1000000007


def computeXOR ( n ):
	
	
	

	
	if n % 4 == 0:
		return n

	
	if n % 4 == 1:
		return 1

	
	if n % 4 == 2:
		return n + 1

	
	return 0

def solve ():
	t = 1
	for it in range (t):
		a,b=num()
		if(a<=1):
			print(computeXOR(b))
		else:
			print(computeXOR(b)^computeXOR(a-1))






if __name__ == "__main__":
	solve ()

Solution (Python):
A,B = map(int,input().split())

def f0n(y):
	if y % 4 == 0:
		return y
	elif y % 4 == 2:
		return 1^y
	elif y % 4 == 3:
		return 0
	else:
		return 1
				
print(f0n(A-1)^f0n(B))

Solution (Python):
def xor(x):
    if x%4==0:
        return x
    elif x%4==1:
        return 1
    elif x%4==2:
        return 1^x
    else:
        return 0

A,B = map(int,input().split())
print(xor(A-1)^xor(B))

Solution (Python):
def F_0_n(n):
    if (n + 1) % 2 == 0:
        return 0 if ((n + 1) // 2) % 2 == 0 else 1
    else:
        return n if (n // 2) % 2 == 0 else n ^ 1


A, B = [ int(x) for x in input().split(" ") ]
 
F_A_B = F_0_n(A - 1) ^ F_0_n(B)

print(F_A_B)

Solution (Python):
a,b = list(map(int,input().split()))
def func(num):
    m = 0
    if num%2 == 0:
        if num%4 == 0:
            m = 1
        return num^m
    else:
        if (num-1)%4 == 0:
            m = 1
        return m^1
print(func(a-1)^func(b))

Solution (Python):
A,B=input().split(" ")
A=int(A)
B=int(B)



if(A%2==1):
	A_=A+1
else:
	A_=A
if(B%2==0):
	B_=B-1
else:
	B_=B

out=((B_-A_+1)//2)%2

if(A%2==1):
	out^=A
if(B%2==0):
	out^=B
print(out)

Solution (Python):
A,B = map(int,input().split())
def cumulativeXor(n):
    if n < 0 : return(0)
    rem = n%4
    q = n-rem
    res = q
    for i in range(1,rem+1):
        res = res ^ (q+i)

    return(res)
print(cumulativeXor(B) ^ cumulativeXor(A-1))

Solution (Python):
A,B = map(int,input().split())

def xor(n):
  ans = 0
  if n % 4 == 0:
    ans = n
  elif n % 4 == 1:
    ans = 1
  elif n % 4 == 2:
    ans = n + 1
  else:
    ans = 0
  return ans

tmp_a = xor(A-1)
tmp_b = xor(B)

print(tmp_a ^ tmp_b)

Solution (Python):
def f(A, B):
    if B % 2 == 1:
        B_kisuu = B
    else:
        B_kisuu = B - 1

    if A % 2 == 0:
        if (B_kisuu - A - 1) % 4 == 0:
            ans = 1
        else:
            ans = 0
    else:
        if (B_kisuu - A) % 4 == 0:
            ans = A
        else:
            ans = A - 1

    if B % 2 == 0:
        ans = ans ^ B

    return ans


A, B = map(int, input().split())
print(f(A, B))

Solution (Python):
from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]

def isOdd(num):
    if num % 2 == 0:
        return False
    else:
        return True

def solve(num):
    if isOdd(num):
        if (num // 2) % 2 == 0:
            return 1
        else:
            return 0
    else:
        return solve(num+1) ^ (num+1) 


print(solve(B) ^ solve(A-1))

Solution (Python):
import itertools


def count_ones(n):
  res = []
  length = n.bit_length()
  power = 1
  while len(res) < length:
    d, m = divmod(n, 2**power)
    num_ones = 2**(power-1) * d + max(0, m + 1 - 2**(power-1))
    res.append(num_ones)
    power += 1
  return res

A, B = map(int, input().split())
if B == 0:
  print(0)
else:
  ones_A = count_ones(A)
  ones_B = count_ones(B)

  ones = [nb - na for nb, na in itertools.zip_longest(ones_B, ones_A, fillvalue=0)]

  change = [x % 2 for x in ones[::-1]]
  change = int(''.join(map(str, change)), 2)
  print(A ^ change)

Solution (Python):
def F(n):
    res = 0
    if n % 4 == 0:
        res = n
    elif n % 4 == 1:
        res = 1
    elif n % 4 == 2:
        res = 1^n
    else:
        res = 0
        
    return res

def main():
    A, B = map(int, input().split())
    ans = F(A-1) ^ F(B)

    

    print(ans)

main()

Solution (Python):
a, b = map(int, input().split())
if b%2 == 1:
    F0_b = (b+1) // 2 % 2
else:
    F0_b = (b) // 2 % 2 ^ b
c = a - 1
if (c)%2 == 1:
    F0_c = (c+1) // 2 % 2
else:
    F0_c = (c) // 2 % 2 ^ c

print(F0_b ^ F0_c)

Solution (Python):
def calc0toN(a):
  if a % 2 == 0:
    if a % 4 == 0:
      return a
    else:
      return 1 ^ a
  else:
    if (a + 1) % 4 == 0:
      return 0
    else:
      return 1
A, B = map(int, input().split())
print(calc0toN(A - 1) ^ calc0toN(B))

Solution (Python):
A, B = map(int, input().split())
st = A if (A % 2 == 0) else A + 1

delta = B - st + 1

if (st == A):
    if (delta % 4 == 2):
        print(1)
    elif (delta % 4 == 0):
        print(0)
    elif (delta % 4 == 1):
        print(B)
    else: 
        print(B ^ 1)
else:
    if (delta % 4 == 2):
        print(1 ^ A)
    elif (delta % 4 == 0):
        print(0 ^ A)
    elif (delta % 4 == 1):
        print(B ^ A)
    else: 
        print(B ^ 1 ^ A)

Solution (Python):
def xor(n):
    if n % 2 == 0:
        return ((n // 2) % 2) ^ n
    else:
        return xor(n - 1) ^ n


a, b = map(int, input().split())
print(xor(a - 1) ^ xor(b))

Solution (Python):
A, B = (int(x) for x in input().split())

if A>0:
    A -= 1
    
count = 0

binary_a = [False]*40
binary_b = [False]*40

for i in range(1,40):
    if int((A / (2 ** i))) % 2 == 1:
        if A % 2 == 0:
            binary_a[i] = True
    if int((B / (2 ** i))) % 2 == 1:
        if B % 2 == 0:
            binary_b[i] = True
            
if A%4 == 1 or A%4 ==2:
    binary_a[0] = True
if B%4 == 1 or B%4 ==2:
    binary_b[0] = True
    



for i in range(40):
    if not(binary_a[i] == binary_b[i]):
        count += 2 ** i
        
print(count)

Solution (Python):
A,B=map(int,input().split())
def calc(A):
    if A%4==0:
        return A
    elif A%4==1:
        return 1
    elif A%4==2:
        return A+1
    elif A%4==3:
        return 0
print(calc(A-1)^calc(B))

Solution (Python):
A, B = [int(i) for i in input().split()]

def calc(i):
  rem = i % 4
  if rem == 0:
    return i
  elif rem == 1:
    return 1
  elif rem == 2:
    return i + 1
  elif rem == 3:
    return 0

print(calc(A - 1) ^ calc(B))

Solution (Python):
A,B = map(int,input().split())
def f(n):
    res = 0
    for d in range(1,51):
        mass = (n // pow(2,d))*pow(2,d-1)
        over = max(n % pow(2,d) - pow(2,d-1),0)
        cnt = mass + over
        if cnt % 2 == 1:
            res += pow(2,d-1)
    return res

ans = f(A)^f(B+1)
print(ans)

Solution (Python):
A,B = map(int,input().split())
def f(n):
    res1 = 0
    res2 = 0
    if (n // 2) % 2 == 1:
        res1 = 1
    if n % 2 == 1:
        res2 = n-1
    return res1^res2

ans = f(A)^f(B+1)
print(ans)

Solution (Python):
def tillx(x): 
    if x == '0':
        return '0'
    elif x == '1':
        return '1' 
    rest = len(x)
    last = x[-1]
    result = ''
    for i in range(len(x)-1):
        if rest > 2:
            if x[i] == '1':
                if last == '1':
                    result += '0'
                elif last =='0':
                    result += '1'
            elif x[i] == '0':
                result += '0'
            rest -= 1
        elif rest == 2:
            m = x[i]+x[i+1]
            if m == '00' or m == '11':
                result += '00'
            elif m == '01':
                result  += '01'
            elif m == '10':
                result += '11'
    return result


def resultmake(A,B):
    a = tillx(bin(A-1)[2:])
    b = tillx(bin(B)[2:])
    a = '0'*(len(b)-len(a)) + a
    result = ''
    for i in range(len(b)):
        if int(b[i])-int(a[i]) == 0:
            result += '0'
        else:
            result += '1'
    return int(result,2)

A,B = map(int,input().split())
print(resultmake(A,B))

Solution (Python):

import sys

def cum_xor(n):
    ret = 0
    if n % 4 == 1 or n % 4 == 2:
        ret += 1
    i = 1
    while n >= 2 ** i:
        tmp = n % (2 ** (i + 1))
        if tmp >= 2 ** i and tmp % 2 == 0:
            ret += 2 ** i
        i += 1
    return ret

def solve(A: int, B: int):
    ret = cum_xor(A - 1) ^ cum_xor(B)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    solve(A, B)

if __name__ == '__main__':
    main()

Solution (Python):
def xor(data):
    if not data:
        return 0
    res = data[0]
    for i in range(1,len(data)):
        res ^= data[i]
    return res

A,B = map(int,input().split())
if A == B:
    print(A)
    exit()
num = B-A+1
data = []
cut = 0
if A % 2 == 0:
    cut = (num) // 2
    if cut % 2 == 1:
        data.append(1)
    if num % 2 == 1:
        data.append(B)
else:
    data.append(A)
    cut = (num-1) // 2
    if cut % 2 == 1:
        data.append(1)
    if (num-1) % 2 == 1:
        data.append(B)
ans = xor(data)
print(ans)

Solution (Python):



A,B = map(int,input().split())
def countBit(n, d):
    period = 2**d
    cont = 2**(d-1)
    n_period = n // period
    n_rest = n % period
    n_cont = max(0, n_rest - cont + 1)
    return n_period * cont + n_cont

bit = [0 for i in range(41)]
for i in range(41):
    bit[i] = (countBit(B, i+1) - countBit(max(0, A-1), i+1)) % 2
ans = 0
for i in range(41):
    ans += bit[i] * (2 ** i)
print(ans)

Solution (Python):
def xor_world(A, B):
    if A == 0:
        m  = (B+1) // 2
        pre = 0 if m % 2 == 0 else 1
        if B % 2 == 1: 
            return pre 
        else:
            return pre ^ B
            
    else:   
        return xor_world(0, A-1) ^ xor_world(0, B)
        
        
if __name__ == "__main__":
    A, B = map(int, input().split())
    print(xor_world(A, B))

Solution (Python):
import sys

a, b = map(int, sys.stdin.readline().split())


def check(x):
    if x % 4 == 0:
        return x
    elif x % 2 == 0:
        return x + 1
    elif (x+1)/2 % 2 == 0:
        return 0
    else:
        return 1


a = check(a-1)
b = check(b)
print(a ^ b)

Solution (Python):
def solver(N):
  if N % 2 == 1:
    return oddodd(N)
  else:
    return (N+1) ^ oddodd(N+1)

def oddodd(N):
  return 1 if (N+1)/2 % 2 == 1 else 0 

A,B = map(int,input().split())

print(solver(B) ^ solver(A-1))

Solution (Python):
a,b=map(int,input().split())
j=0
while b>=2**j:
    j+=1
if b==0:
    j=1
k=1
l=[0 for i in range(j)]
bia=[0 for i in range(j)]
A=a
i=0
while A>2**(k-1):
    l[i]=A%(2**k)
    m=(l[i]-2**(k-1))
    if m<=0:
        bia[i]=0
    else:
        if m%2==1:
            bia[i]=1
        else:
            bia[i]=0
    k+=1
    i+=1
if (A//2)%2==0:
    bia[0]=0
else:
    bia[0]=1
k=1
l=[0 for i in range(j)]
bib=[0 for i in range(j)]
B=b+1
i=0
while B>2**(k-1):
    l[i]=B%(2**k)
    m=(l[i]-2**(k-1))
    if m<=0:
        bib[i]=0
    else:
        if m%2==1:
            bib[i]=1
        else:
            bib[i]=0
    k+=1
    i+=1
if (B//2)%2==0:
    bib[0]=0
else:
    bib[0]=1
ans=0
for i in range(j):
    if bia[i]==bib[i]:
        ans=ans
    else:
        ans+=2**i
print(ans)

Solution (Python):
import math

A, B = [int(i) for i in input().split()]
exclusiveA = 0
exclusiveB = 0
B += 1
for i in range(len(bin(B)) - 2):
    factorialNum = int(math.pow(2, i))
    numA = A // (factorialNum * 2) * factorialNum
    numA += max(A % (factorialNum * 2) - factorialNum, 0)
    numB = B // (factorialNum * 2) * factorialNum
    numB += max(B % (factorialNum * 2) - factorialNum, 0)
    if numA % 2 == 1:
        exclusiveA += factorialNum
    if numB % 2 == 1:
        exclusiveB += factorialNum

print(exclusiveB ^ exclusiveA)

Solution (Python):
A, B = list(map(int, input().split(' ')))

def f(n):
    if n % 2 == 0:
        m = n // 2
        if m % 2 == 0:
            return 0 ^ n
        else:
            return 1 ^ n
    else:
        m = (n+1) // 2
        if m % 2 == 0:
            return 0
        else:
            return 1

if A == 0:
    print(f(B))
else:
    print(f(A-1) ^ f(B))

Solution (Python):
def f(n):
    if n%4==0: return n
    if n%4==1: return 1
    if n%4==2: return n+1
    else: return 0
a,b=map(int,input().split())
print(f(a-1)^f(b))

Solution (Python):



def g(x):
    if x % 2 == 1:
        return 1 if x % 4 == 1 else 0
    if x % 4 == 2:
        return x | 1
    return x


def solve(a, b):
    if a == 0:
        return g(b)
    else:
        return g(b) ^ g(a - 1)


def main():
    a, b = input().split()
    a = int(a)
    b = int(b)

    print(solve(a, b))


if __name__ == '__main__':
    main()

Solution (Python):
def f(n):
	return n^f(n-1) if n%4 else n
a,b=map(int,input().split())
print(f(a-1)^f(b))

Solution (Python):
A, B = map(int, input().split())
ans = 0
flag = False
if A%2 == 1:
    flag = True
    A += 1
diff = B-A+1
if diff%4 == 0:
    ans = 0
elif diff%4 == 1:
    ans = B
elif diff%4 == 2:
    ans = 1
else:
    ans = B^1
if flag: ans = ans^(A-1)
print(ans)

Solution (Python):


def xor_from0(n):
    a = ~0
    if(n&1): a = 0
    ans = ((n >> 1) & a) << 1
    one = (n&1) ^ ((n&2)>>1)
    return ans ^ one

a, b = map(int, raw_input().split())
print(xor_from0(b) ^ xor_from0(a-1))

Solution (Python):
import math

AB = list(map(int,input().strip().split()))
A = AB[0]
B = AB[1]


def solve_odd(a):
    return math.floor((a + 1) / 2) % 2


def solve(a):
    if a % 2 == 1:
        return solve_odd(a)
    else:
        return solve_odd(a + 1) ^ (a + 1)


print(solve(B) ^ solve(A - 1))

Solution (Python):
import numpy as np


def sum_to_num(num):
    if num == 0:
        return 0
    
    elif num == 1:
        return 1
    elif num == 2:
        return 3
    elif num == 3:
        return 0

    base = 2 ** (len('{:b}'.format(num)) - 1)

    if num % 2 == 0:
        return sum_to_num(num - base) + base
    else:
        return sum_to_num(num - base)

A, B = map(int, input().split())
if A == 0:
    print(sum_to_num(B))
else:
    print(np.bitwise_xor(sum_to_num(B), sum_to_num(A - 1)))

Solution (Python):

def fun(x):
	res = [x, 1, x+1, 0]
	return res[x%4]








a, b = map(int, input().split())
print(fun(b)^fun(a-1))

Solution (Python):
from sys import exit

A, B = map(int, input().split())


def get_xor(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return 1 + x
    elif x % 4 == 3:
        return 0


ans = get_xor(A - 1) ^ get_xor(B)

print(ans)

Solution (Python):
a, b = map(int, input().split())
ta = list(map(int, list(bin(a))[:1:-1]))
tb = list(map(int, list(bin(b))[:1:-1]))
S  = [0]*40
E  = [0]*40
for i in range(len(ta)):
    S[i]=ta[i]
for i in range(len(tb)):
    E[i]=tb[i]
sum=0
for i in range(1,40):
    odd =0
    sodd=0
    eodd=0
    m0=a%(2**(i+1))
    M0=b%(2**(i+1))
    m1=a//(2**(i+1))
    M1=b//(2**(i+1))
    if m1==M1:
        if(S[i]==0 and E[i]==1 and b%2==0):
            odd = 1
        elif(S[i]==1 and (b-a)%2==0):
            odd = 1
    else:
        if(S[i]==0 and E[i]==1 and b%2==0):
            odd = 1
        elif(S[i]==1 and E[i]==0 and a%2==1):
            odd = 1
        elif(S[i]==1 and E[i]==1):
            sodd = 1 if (a%2==1) else 0
            modd = 1 if (b%2==0) else 0
            odd = sodd^modd
    sum+=(2**i)*odd

if((a//4)!=(b//4)):
    if(a%4>1 and (b%4==0 or b%4==3)):
        sum+=1
    elif(a%4<=1 and (b%4==1 or b%4==2)):
        sum+=1
else:
    if((b-a)==1 or ((b-a)==2 and a%2==0)):
        sum+=1

print(sum)

Solution (Python):
A , B = map(int,input().split())
def XOR_0_to_n(n):
    if n % 2 == 0:
        if (n // 2) % 2 == 0:
            return 0 ^ n
        else:
            return 1 ^ n
    else:
        if ((n-1) // 2) % 2 == 0:
            return 0 ^  n ^ (n-1)
        else:
            return 1 ^ n ^ (n -1)
print(XOR_0_to_n(A-1)^XOR_0_to_n(B))

Solution (Python):
def computeXOR(n) : 
    if n % 4 == 0 : 
        return n 
  
    if n % 4 == 1 : 
        return 1
  
    if n % 4 == 2 : 
        return n + 1
  
    return 0

A, B = (int(x) for x in raw_input().split())
print ( computeXOR(A-1) ^ computeXOR(B) )

Solution (Python):
def xor(val):
	if val < 0: return 0
	mod = val % 4
	if mod == 0: return val
	elif mod == 1: return 1
	elif mod == 2: return val + 1
	else: return 0

A, B = map(int, raw_input().split())
print xor(A - 1) ^ xor(B)

Solution (Python):
def G(x):
  ret = 1 if x%4 in (1, 2) else 0
  for p in range(1,64):
    r = x%(2**(p+1))
    if r >= (2**p) and r % 2 == 0:
      ret += 2**p
  return ret
A, B = map(int,input().split())
print(G(B)^G(A-1))

Solution (Python):
def f(n):
    n += 1
    ans = 0
    for i in range(n - (n&0b11), n):
        ans ^= i
    return ans

A, B = map(int, input().split())
print(f(A-1)^f(B))

Solution (Python):
def f(i):
    cnt = (i + 1) // 2
    ans = cnt % 2
    if (i % 2 == 0):
        ans ^= i
    return ans


a, b = map(int, input().split())
print(f(a - 1) ^ f(b))

Solution (Python):
A, B = map(int, input().split())
def f(n):
  if n % 2 == 0:
    if n % 4 == 0:
      return n
    else:
      return 1 ^ n
  else:
    if (n+1) % 4 == 0:
      return 0
    else:
      return 1
A = f(A-1)
B = f(B)
print(A^B)

Solution (Python):
tmp = input()
A = int(tmp.split()[0])
B = int(tmp.split()[1])
 
res = 0
if A%2 == 0:
	if B%2 == 0:
		res = B^(int((B-A)/2)%2)
	else :
		res = int((B-A+1)/2)%2
else :
	if B%2 == 0:
		res = A^B^(int((B-A-1)/2)%2)
	else :
		res = A^(int((B-A)/2)%2)
print(res)

Solution (Python):
A,B = list(map(int, input().split()))

range = B - (A - 1)

result = 0

if A % 2 == 1:
    range -= 1
    result = A

if B % 2 == 0:
    range -= 1
    result ^= B


if range % 4 != 0:
    result ^= 1

print(result)

Solution (Python):
a, b = map(int, input().split())                                                                               

ans = 0 
def f(n):
    if n % 2 == 1:
        num_pairs = (n + 1) // 2
        return num_pairs % 2 
    else:
        num_pairs = (n + 1) // 2
        return (num_pairs % 2) ^ n 

print(f(a-1) ^ f(b))

Solution (Python):
def xor_one(a):
    k=change_binary(a)

    if k[len(k)-1]=="0":
        ad="1"

    else:
        ad="0"
    m="0b"+k[:len(k)-1]+ad
    return int(m,0)
    
    

def binary_fanction(a):
    r=(a+1)//2
    if (a+1)%2==0:
        return r%2
    else:
        k=change_binary(a)
        if r%2==0:
            return a
        else :
            return xor_one(a)

def change_binary(a):
    k=str(bin(a)).replace("0b","")
    return k

def exclusive_or(a,b):
    big_bin=change_binary(max(a,b))
    small_bin=change_binary(min(a,b))
    small_bin="0"*(len(big_bin)-len(small_bin))+small_bin
    k=""
    

    for i in range(len(small_bin)):
        k=k+str(int(big_bin[i])^int((small_bin[i])))
        
    k="0b"+k
    return int(k,0)

a,b=map(int,input().split())
print(exclusive_or(binary_fanction(a-1),binary_fanction(b)))

Solution (Python):
ab = list(map(int, input().split()))
a = ab[0]
b = ab[1]
answer = 0

for i in range(40):
    if i != 0:
        a_mod = a % 2 ** (i + 1)
        b_mod = b % 2 ** (i + 1)
        if a_mod > 2 ** i:
            a_mod_1 = 2 ** (i + 1) - a_mod
        else:
            a_mod_1 = 2 ** i
        if b_mod >= 2 ** i:
            b_mod_1 = b_mod - 2 ** i + 1
        else:
            b_mod_1 = 0
        num_of_1 = a_mod_1 + b_mod_1
    else:
        if b % 2 == 1:
            if (b - a) % 4 == 2 or (b - a) % 4 == 3:
                num_of_1 = 0
            else:
                num_of_1 = 1
        else:
            if (b - a) % 4 == 1 or (b - a) % 4 == 2:
                num_of_1 = 1
            else:
                num_of_1 = 0
    answer = answer + (num_of_1 % 2) * (2 ** i)

print(answer)

Solution (Python):
import numpy as np

A,B = map(int,input().split())
def f(x):
    rx = x%4
    bin_f = 0
    for i in range(rx+1): 
        bin_f = bin_f ^ (x-i)
    return bin_f

print(f(A-1)^f(B))

Solution (Python):
a, b = map(int, input().split())

ans = 0
for i in a - 1, b:
    if i % 4 == 0:
        ans ^= i
    elif i % 4 == 1:
        ans ^= 1
    elif i % 4 == 2:
        ans ^= i + 1
    else:
        ans ^= 0
        
print(ans)

Solution (Python):


A, B = map(int, input().split())

Fa = 0 if A == 0 else (((A - 2) // 2 - 1) % 2 if (A - 1) % 2 == 1 else (A - 1) ^ ((A - 2) // 2 - 1) % 2)
Fb = ((B - 1) // 2 - 1) % 2 if B % 2 == 1 else B ^ ((B - 1) // 2 - 1) % 2

print(Fa ^ Fb)

Solution (Python):


import math

A, B = map(int, input().split())

if A == B:
    print(A)
else:
    ans = ((B - A + 2) % 4) // 2 if A % 2 == 1 else ((B - A + 1) % 4) // 2
    for i in range(1, int(math.log(B, 2)) + 1):
        D, Dp1 = 2 ** i, 2 ** (i + 1)
        a, b = A % Dp1, B % Dp1
        ad, bd = a // D, b // D

        if a == b:
            ans += D * ad
        elif ad == 0 and bd == 0:
            ans += 0
        elif ad == 0 and bd == 1:
            ans += D * ((b + 1) % 2)
        elif ad == 1 and bd == 0:
            ans += D * (a % 2)
        elif ad == 1 and bd == 1:
            ans += D * ((a - b + 1) % 2)

    print(ans)

Solution (Python):
a, b = map(int, input().split())
def xor0toN(N):
    if N % 2 == 1:
        return int((N+1)/2) % 2
    else:
        return int((N+1)/2) % 2 ^ N
print(xor0toN(a - 1) ^ xor0toN(b))

Solution (Python):
a,b = map(int,input().split())

def XOR_SUM(X):
    ans = 0
    if X % 4 == 0:
        ans = X
    elif X % 4 == 1:
        ans = 1
    elif X % 4 == 2:
        ans = X+1
    elif X % 4 == 3:
        ans = 0
    return ans
    
print(XOR_SUM(a-1)^XOR_SUM(b))

Solution (Python):
a, b = map(int, (input().split()))
if a % 2 ==0:
    if b % 2 ==0:
        print(int((b - a) /2 % 2) ^ b)
    else:
        print(int((b - a + 1)/2 % 2))
else:
    if b % 2 ==0:
        print(a ^ b ^ int((b - a)/2 % 2))
    else:
        print(a ^ int((b - a)/2 %2))

Solution (Python):
def f(i):
    cnt = (i + 1) // 2
    ans = cnt % 2
    if (i % 2 == 0):
        ans ^= i
    return ans


def main():
    A, B = map(int, input().split())
    print(f(A - 1) ^ f(B))


main()

Solution (Python):
a, b = list(map(int, input().split()))
d = b - a
if d == 0:
    ans = a
elif d == 1:
    ans = a ^ b


if a % 2 == 1:
    if d == 2:
        ans = a ^ 1
    elif d == 3:
        ans = a ^ b ^ 1
    elif d>3:
        ans=a
        r=d%4
        if r==0:
            ans^=0
        elif r==1:
            ans^=0^b
        elif r==2:
            ans^=0^1
        else:
            ans^=0^1^b

elif a % 2 == 0:
    if d == 2:
        ans = b ^ 1
    elif d == 3:
        ans = 0
    elif d>3:
        ans=b
        r=d%4
        if r==0:
            ans^=0
        elif r==1:
            ans^=b-1
        elif r==2:
            ans^=1
        else:
            ans=0
print(ans)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


"""
h,w = LI()
y,x = LI()
print(h*w-h*x-w*y+y*x)
"""


"""
n,m,c = LI()
b = LI()
a = LIR(n)
ans = 0
for i in range(n):
    d = c
    for k in range(m):
        d += b[k]*a[i][k]
    if d > 0:
        ans += 1
print(ans)
"""




"""
n,m = LI()
v = LIR(n)
v.sort(key = lambda x:x[0])
ans = 0
k = 0
for a,b in v:
    if k+b >= m:
        ans += (m-k)*a
        print(ans)
        quit()
    ans += b*a
    k += b
"""


def f(n):
    if n%4 == 3:
        return 0
    if n%4 == 0:
        return n
    if n%4 == 1:
        return 1
    return n+1
a,b = LI()
print(f(b)^f(a-1))

Solution (Python):
def f(n):
    if n%2 == 0:
        return (n//2)%2 ^ n
    else:
        return ((n+1)//2)%2

a,b = map(int,input().split())
print(f(a-1)^f(b))

Solution (Python):
a, b = map(int, input().split())

N = b - a + 1

if a%2 == 0:
    if N%4 == 0:
        print(0)
    elif N%4 == 1:
        print(b)
    elif N%4 == 2:
        print(1)
    else:
        print(b + 1)
else:
    if N%4 == 0:
        print(a ^ b ^ 1)
    elif N%4 == 1:
        print(a)
    elif N%4 == 2:
        print(a ^ b)
    else:
        print(a ^ 1)

Solution (Python):


from sys import stdin

A, B = list(map(int, stdin.readline().split()))

N = B - A + 1

if A & 1 != 1:
    if N % 2 == 0:
        if N % 4 == 0:
            print(0)
        else:
            print(1)
    else:
        if (N - 1) % 4 == 0:
            print(B ^ 0)
        else:
            print(B ^ 1)
else:
    if (N - 1) % 2 == 0:
        if (N - 1) % 4 == 0:
            print(A ^ 0)
        else:
            print(A ^ 1)
    else:
        if (N - 2) % 4 == 0:
            print(A ^ B ^ 0)
        else:
            print(A ^ B ^ 1)

Solution (Python):
a, b = map(int, input().split())
f = lambda x: ((x+1)//2)%2 if x%2 else ((x//2)%2)^x
print(f(a-1)^f(b))

Solution (Python):
import re
import numpy as np

A, B = [int(item) for item in re.split(r"\s", input())]

print(((A % 2) * (A - 1)) ^ (((A) // 2) % 2) ^ (((B + 1) % 2)) * (B) ^ (((B + 1) // 2) % 2))

Solution (Python):
import sys
A,B=map(int,input().split())
if B-A<100:
    s=0
    for i in range(A,B+1):
        s^=i
    print(s)
    sys.exit()
s=(A//4)*4+4
t=(B//4)*4
u=0
for i in range(A,s):
    u^=i
for i in range(t,B+1):
    u^=i
print(u)

Solution (Python):
def z_to_n(n):
    m4=n%4
    if m4==0:
        return n
    elif m4==1:
        return 1
    elif m4==2:
        return n+1
    else:
        return 0
a,b=map(int,input().split(" "))
print(z_to_n(a-1)^z_to_n(b))

Solution (Python):
def main():
    A, B = map(int, input().split())

    ans = f(A, B)
    print(ans)


def TLE(A, B):
    ans = A
    for y in range(A+1, B+1):
        ans ^= y

    return ans


def f(A, B):
    """
    2^0: 0001
    2^1: 0010
         0011
    2^2: 0100
         0101
         0110
         0111
    2^3: 1000

    連番のdiff:
        1増えるので,2進数では下1桁は必ず異なる
        桁上りを考慮するとすべて変わる可能性もある
        1/2個,下二桁以外は同じになるので0になる
        偶数ベースに奇数との比較をする場合は 000...01
            0^1: 000 001, 001
            2^3: 010 010, 001
            4^5: 100 101, 001
            6^7: 110 111, 001

            この 01 になる偶数奇数のペア数が
            偶数個なら xor=0
            奇数個なら xor=1
    その次
         1- 2: 001- 010 -> 011
         2- 3: 010- 011 -> 001
         3- 4: 011- 100 -> 111
        11-12:1011-1100 -> 111

      a=0^1^2^3^4^5
      b=0^1^2^3^4^5^6^7^8
    a^b=            6^7^8
    """
    def xor_from_zero(x):
        if x == 0:
            return 0
        if x % 2 == 1:
            
            return (x + 1) // 2 % 2
        else:
            
            return x ^ (x // 2 % 2)

    a = xor_from_zero(A - 1)
    b = xor_from_zero(B)
    ans = a ^ b
    return ans


if __name__ == "__main__":
    main()