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



def main():
	a , b = map(int , input().split())
	a=a-1
	rem = a%4
	x, y =0 ,0
	if rem==0:
		x=a   
	elif rem==1:
		x=1
	elif rem==2: 
		x = a+1		
	else:
		x=0		
	rem = b%4
	if rem ==0:
		y=b
	elif rem==1:
		y=1
	elif rem==2:
		y=b+1
	else:
		y=0
	print(x^y)
if __name__=="__main__":
	main()

Solution (Python):

def main():
	a , b = map(int , input().split())
	a=a-1
	rem = a%4
	x, y =0 ,0
	if rem==0:
		x=a
	elif rem==1:
		x=1
	elif rem==2:
		x = a+1
	else:
		x=0
	rem = b%4
	if rem ==0:
		y=b
	elif rem==1:
		y=1
	elif rem==2:
		y=b+1
	else:
		y=0
	print(x^y)
if __name__=="__main__":
	main()

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def f(B):
    '''
    000  = 1   = 0
    001
    010  = 1
    011
    100  = 1
    101
    '''
    B += 1
    if B%4 == 0:
        return 0
    if B%4 == 1:
        return B-1
    if B%4 == 2:
        return 1
    return (B-1)^1


def solve():
    A, B = read_ints()
    return f(A-1)^f(B)


if __name__ == '__main__':
    print(solve())

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))

def g(X):
    """
    000
    001
    010
    011
    100
    101
    110
    111
    """
    p = 1
    i = 39
    digits = [0]*40
    N = X+1
    while i > -1:
        digits[i] = N//(2*p)*p
        if N%(2*p)-p > 0:
            digits[i] += N%(2*p)-p
        p *= 2
        i -= 1
    answer = 0
    p = 1
    for d in digits[::-1]:
        if d%2 == 1:
            answer += p
        p *= 2
    return answer


def solve():
    """
    f(A, B) = A^...^B
    g(A) = 0^...^A
    g(B) = 0^...^B

    f(A, B) = g(A-1)^g(B)
    f(0, B) = g(B)
    """
    A, B = read_ints()
    if A == 0:
        return g(B)
    return g(A-1)^g(B)


if __name__ == '__main__':
    print(solve())

Solution (Python):
a,b=map(int,input().split())
f=lambda x:[x,1,x+1,0][x%4]
print(f(b)^f(a-1))

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

res = 0
if a % 2 == 1:
    res ^= a
    a += 1
if b % 2 == 0:
    res ^= b
    b -= 1
print(res ^ ((b-a+1)//2)%2)

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

def f(x):
  res = 0
  while x % 4 != 3:
    res ^= x
    x -= 1
  return res

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

Solution (Python):
a, b = map(int, input().split())
def xor(x):
    num = [0 for i in range(41)]
    for i in range(41):
        temp = (x + 1) // (2 ** (i + 1))
        temp2 = (x + 1) % (2 ** (i + 1))
        num[i] += temp * (2 ** i)
        num[i] += max(temp2 - 2 ** i, 0)
    return num
temp = [0 for i in range(41)]
temp2 = xor(b)
temp3 = xor(a - 1)
for i in range(41):
    temp[i] += temp3[i]
    temp[i] -= temp2[i]
    temp[i] %= 2
ans = 0
for i in range(41):
    ans += temp[i] * 2 ** i
print(ans)

Solution (Python):


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

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

ans = func(a - 1) ^ func(b)
print(ans)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

a, b = MAP()

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

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

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

a, b = MAP()
a -= 1

s = deque()
tmp = (b+1)//2-(a+1)//2
s.appendleft(str(tmp % 2))
i = 1
while 2**i <= b:
    x = max(0, a%(2**(i+1)) - (2**i-1))
    y = max(0, b%(2**(i+1)) - (2**i-1))
    tmp = y - x
    s.appendleft(str(tmp % 2))
    i += 1
t = list(s)
ans = "".join(t)
print(int(ans, 2))

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


"""
10**12 < 2**40
任意の整数について、n ^ (n+1) = 1
"""
def f(n):
    if n%2!=0:
        if ((n+1)//2)%2!=0:
            return 1
        else:
            return 0
    else:
        if (n//2)%2!=0:
            return n ^ 1
        else:
            return n

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

Solution (Python):

import sys,os
from collections import defaultdict, deque
from math import gcd, ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    A,B = LMIIS()
    if A & 1:
        if B & 1:
            
            print(A^(B-A)//2%2)
        else:
            
            print(A^((B-A-1)//2%2)^B)
    else:
        if B & 1:
            
            print((B-A+1)//2%2)
        else:
            
            print((B-A)//2%2^B)



    

if __name__ == '__main__':
    main()

Solution (Python):
from math import log2

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

def bitpos(x,digit=1):
  bit = x % (2**digit) // (2**(digit-1))
  pos = x % (2**digit)
  return int(bit),pos

if B == 0:
  print(0)
  exit()
else:
  max_digit=int(log2(B))+1

xor=[]
for i in range(max_digit):
  abit,apos = bitpos(A,i+1)
  bbit,bpos = bitpos(B,i+1)
  if i == 0:
    ar,br = A%4,B%4
    if (ar,br) in {(0,1),(0,2),(1,1),(1,2),(2,3),(2,0),(3,3),(3,0)}:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  
  if abit == 0 and bbit==0:
    xor.append('0')
    continue
  elif abit == 1 and bbit==0:
    if apos % 2 == 1:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  elif abit == 0 and bbit == 1:
    if bpos % 2 == 0:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  else:
    if abs(apos-bpos) % 2 == 1:
      xor.append('0')
      continue
    else:
      xor.append('1')
      continue
xor = xor[::-1]
print(int(''.join(xor),2))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



A, B = MAP()

def xor_cal(N):
	if N%4 == 0:
		return N
	elif N%4 == 1:
		return 1
	elif N%4 == 2:
		return N^1
	else:
		return 0

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



A, B = MAP()

def xor_cal(N):
	if N%2 == 1:
		return (N+1)//2%2
	else:
		return xor_cal(N-1)^N

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



A, B = MAP()
A -= 1
n = len(str(bin(B)))-2
a = [0]*n
b = [0]*n

def cnt_bit(cnt, N):
	for i in range(n):
		p = N//(2**(i+1)) * 2**i
		q = N%(2**(i+1))
		if 2**i <= q:
			p += min(2**i, q-(2**i-1))
		cnt[i] = p

cnt_bit(a, A)
cnt_bit(b, B)

ans = 0
for i in range(n):
	if (b[i]-a[i])%2:
		ans += 2**i

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def g(n):
    if n == -1:
        return 0
    if n == 0:
        return 0
    if n == 1:
        return 1

    b = bin(n)[2:]
    res = 0
    
    if b[-2:] == "10":
        res += 3
    
    elif b[-2:] == "11":
        pass
    
    else:
        res += int(b[-1])

    for i in range(len(b) - 2):
        if b[i] == "0":
            continue
        if b[-1] == "0":
            res += 1 << (len(b) - 1 - i)
    return res


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

    if A == B:
        ans = A
    else:
        ans = g(A - 1) ^ g(B)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def f(x):
        if x % 2:
            if x == 1:
                return 1
            elif max(0, x - 3) % 4 == 0:
                return 0
            else:
                return 1
        else:
            t = f(x - 1)
            return t ^ x

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

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


if __name__ == '__main__':
    resolve()

Solution (Python):

for i in range(pow(10,6)):
    pass


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

Solution (Python):
a,b=map(int,input().split())
a-=1
a_=[a,1,a+1,0]
b_=[b,1,b+1,0]
print(a_[a%4]^b_[b%4])

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

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


























def calc(a):
    t = (a + 1) // 2
    ans = t % 2
    if a % 2 == 0:
        ans = ans ^ a
    return ans

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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

def calc(a):
    if a <= 0: return 0
    
    
    a += 1
    
    ans = 0
    
    
    
    for i in range(50):
        
        
        loop = (1 << (i+1))
        cnt = a//loop * loop//2 
        
        cnt += max(0, (a%loop) - (loop//2))
        
        if cnt%2 == 1:
            ans += 1<<i
            
    return ans
        
ans = calc(a-1)^calc(b)

print(ans)

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

if A==B:
	print(A)
	exit()

if A%2==1 and B%2==1:
	even=(B-A)//2
else:
	even=(B-A)//2+1

if even%2==0:	
	if A%2==1 and B%2==0:
		print(A^B^1)
	elif A%2==1 and B%2==1:
		print(A)
	elif A%2==0 and B%2==1:
		print(0)
	elif A%2==0 and B%2==0:
		print(B^1)
else:
	if A%2==1 and B%2==0:
		print(A^B)
	elif A%2==1 and B%2==1:
		print(A^1)
	elif A%2==0 and B%2==1:
		print(1)
	elif A%2==0 and B%2==0:
		print(B)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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

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

if a > 0:
    fa = rep_xor(a-1)
    fb = rep_xor(b)
    ans = fa^fb
else:
    fb = rep_xor(b)
    ans = fb

print(ans)

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

A, B = map(int, input().split())
def xor_sum(n):
    ans = 0
    if n % 2:
        ans = ((n+1)//2) % 2
    else:
        ans = (n//2) % 2
        ans ^= n
    return ans

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

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

Solution (Python):
def xor_0_n(n):
    if n % 2 == 1 and (n//2) % 2 == 1:
        n = 0
    elif n % 2 == 1 and (n//2) % 2 == 0:
        n = 1
    elif n % 2 == 0 and (n//2) % 2 == 1:
        n ^= 1
    return n
  
a, b = map(int,input().split())

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

Solution (Python):
a1,b1=map(int,input().split())
a=[0]*40
b=[0]*40
A=a1
B=b1
for i in range(1,41):
    a[-i]=a1%2
    b[-i]=b1%2
    a1=a1//2
    b1=b1//2
ans=[0]*40
if a[-1]==1:
    if (a[-2]-b[-2])%2==0:
        if b[-1]==1:
            ans[-1]=1
    else:
        if b[-1]==0:
            ans[-1]=1
else:
    if (a[-2]-b[-2])%2==0:
        if b[-1]==1:
            ans[-1]=1
    else:
        if b[-1]==0:
            ans[-1]=1
for i in range(2,41):
    if a[-i]==1 and a[-1]==1:
        if b[-i]==1 and b[-1]==0:
            ans[-i]=0
        else:
            ans[-i]=1
    else:
        if b[-i]==1 and b[-1]==0:
            ans[-i]=1
        else:
            ans[-i]=0
ans1=0
for i in range(1,41):
    ans1+=(2**(i-1))*ans[-i]
print(ans1)

Solution (Python):
a, b = map(int, input().split())
p, q = (a+1)//4, (b+1)//4
x, y = (a+1)%4, (b+1)%4
if abs(a-b) < 4:
    ans = a
    for i in range(a+1, b+1):
        ans ^= i
    print(ans)

else:
    if x == 0:
        ans = a

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

    elif x == 1:
        ans = 0

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

    elif x == 2:
        ans = a
        ans ^= (a+1)
        ans ^= (a+2)

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

    elif x == 3:
        ans = a
        ans ^= (a+1)

        if y == 1:
            ans ^= b
        elif y == 2:
            ans ^= b
            ans ^= (b-1)
        elif y == 3:
            ans ^= b
            ans ^= (b-1)
            ans ^= (b-2)
        elif y == 0:
            ans ^= 0

        print(ans)

Solution (Python):





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

    def xor_1_to_x(x):
        output = [0] * 40

        for k in range(40):
            output[k] = (2**k)*((x+1)//(2**(k+1)))
            output[k] += max(0, (x+1) - ((2**(k+1))*((x+1)//(2**(k+1))) + (2**k)))

        return output

    xor_B = xor_1_to_x(B)
    xor_A_m1 = xor_1_to_x(A-1)
    xor_AtoB = [None] * 40
    for k in range(40):
        xor_AtoB[k] = xor_B[k] - xor_A_m1[k]
        xor_AtoB[k] %= 2

    ans = 0
    for k in range(40):
        ans += xor_AtoB[k] * (2**k)

    return ans


print(main())

Solution (Python):
def main():
    A, B = map(int, input().split())
    res = 0
    if A % 2 == 0 and B % 2 == 1:
        res = ((B - A + 1) // 2) % 2
    elif A % 2 == 0 and B % 2 == 0:
        res = (((B - A) // 2) % 2)^B
    elif A % 2 == 1 and B % 2 == 0:
        res = (((B - A - 1) // 2) % 2)^A^B
    else:
        res = (((B - A) // 2) % 2)^A

    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



bn = 2 ** 42

def bb(v):
	ra = bin(v+bn)[3:][::-1]
	return ra

def cc(v, i):
	r = pow(2, i)
	vn = v+1
	vna = vn //(2*r)
	vnb = vn % (2*r)
	ret = vna * r
	ret += max(vnb - r, 0)
	
	return ret

def main():
	
	f, t = tin()
	
	ret = 0
	for i, _ in enumerate(bb(0)):
		r = pow(2, i)
		nn = cc(t,i) - cc(f-1, i)
		if (nn) % 2 == 1:
			
			ret += r
	return ret
		
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
a,b = map(int,input().split())
ans = 0
if b-a<=10:
    for i in range(a,b+1):
        ans ^= i
else:
    while a % 4 != 0:
        ans ^= a
        a += 1
    while b % 4 != 3:
        ans ^= b
        b-= 1
print(ans)

Solution (Python):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007
    
    A, B = mi()
    A -= 1
    ans = 0
    for i in [A, B]:
        if i % 2 == 1:
            
            if (i // 2) % 2 == 1:
                i = 0
            
            else:
                i = 1
        else:
            if ((i-1) // 2) % 2 == 1:
                i = 0 ^ i
            else:
                i = 1 ^ i
        ans ^= i
        
    print(ans)

    return

main()

Solution (Python):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007
    
    A, B = mi()
    
    A -= 1
    if A % 2 == 1:
        
        if (A // 2) % 2 == 1:
            A = 0
        
        else:
            A = 1
    else:
        if ((A-1) // 2) % 2 == 1:
            A = 0 ^ A
        else:
            A = 1 ^ A

    if B % 2 == 1:
        if (B // 2) % 2 == 1:
            B = 0
        else:
            B = 1
    else:
        if ((B-1) // 2) % 2 == 1:
            B = 0 ^ B
        else:
            B = 1 ^ B

    print(A ^ B)

    return

main()

Solution (Python):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007
    
    A, B = mi()
    
    A -= 1
    if A % 2 == 1:
        
        if (A // 2) % 2 == 1:
            A = 0
        
        else:
            A = 1
    else:
        if (A // 2) % 2 == 0:
            A = 0 ^ A
        else:
            A = 1 ^ A

    if B % 2 == 1:
        if (B // 2) % 2 == 1:
            B = 0
        else:
            B = 1
    else:
        if (B // 2) % 2 == 0:
            B = 0 ^ B
        else:
            B = 1 ^ B

    print(A ^ B)

    return

main()

Solution (Python):



import sys
readline = sys.stdin.readline

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

def f(x):
  res = 0
  while x % 4 != 3:
    res ^= x
    x -= 1
  return res

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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


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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

bt = 0
if b % 2:
    bt = ((b + 1) // 2) % 2
else:
    bt = (b // 2) % 2
    bt ^= b

at = 0
if (a - 1) % 2:
    at = (a // 2) % 2
else:
    at = ((a - 1) // 2) % 2
    at ^= (a - 1)

print(bt ^ at)

Solution (Python):

a, b = map(int, input().split())
"""
bit ごとにみる
b-a = even and a%2 == 0 => 1
else: 0

（0 ~ b madeno 個数）－　（0 ~ a-1 madeno 個数）
1の位は (b+1)/2
10の位は (b+1)/4 + max((b+1)%4-2,0)
100の位
"""

ans = 0

if b % 2 == 1:
    ans = (b + 1) // 2 % 2
else:
    ans = b ^ (b // 2 % 2)


if a == 0:
    print(ans)
else:
    tmp = 0
    if (a - 1) % 2 == 1:
        tmp = a // 2 % 2
    else:
        tmp = (a - 1) ^ ((a - 1) // 2 % 2)
    ans = ans ^ tmp
    print(ans)

Solution (Python):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


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


a, b = LI()

ans = ruiseki_xor(b) ^ ruiseki_xor(a - 1)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def g(x):
    if x <= 0:
        return 0
    tmp = x
    n = 0
    while tmp > 0:
        tmp //= 2
        n += 1
    l = [0]*n
    for i in range(n):
        if i==0:
            l[i] = 1 if x%4==1 or x%4==2 else 0
        else:
            l[i] = max(x%(1<<(i+1))-(1<<i)+1, 0)%2
    return sum(l[i]*(2**i) for i in range(n))


def main():
    A, B = mi()
    print(g(B)^g(A-1))

if __name__ == '__main__':
    main()

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

def f(x):
    if x%2==0:
        if (x//2)%2==0:
            ans=x
        else:
            ans=1^x
    else:
        ans=f(x-1)^x
    return ans

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

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

a=A%4
b=B%4

ans=0
cnt=0
for i in range(a,4):
    ans=ans^(A+cnt)
    cnt+=1
cnt=0
for i in range(b,-1,-1):
    ans=ans^(B-cnt)
    cnt+=1
print(ans)

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












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

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

Solution (Python):
A, B = map(int, input().split())
ans = 0
for i in range(40):
    
    tmp = (B-A) // 2**(i+1) * 2**i
    p = A%(2**(i+1))
    q = (B-A)%(2**(i+1))
    
    tmp += max(min(p+q,2**(i+1)-1) - max(p,2**i)+1,0)
    tmp += max(min(p+q,2**(i+1)-1 + 2**(i+1)) - max(p,2**i + 2**(i+1))+1,0)
    ans += (tmp%2) * 2**i
print(ans)

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    A, B = NMI()
    C = [[0]*2 for _ in range(42)]
    B = B + 1
    for i in range(42):
        tmp = B - (B // (2**(i+1))) * 2**(i+1)
        if tmp < 2**i:
            C[i][0] = tmp + (B // (2**(i+1))) * 2**i
            C[i][1] = (B // (2 ** (i + 1))) * 2 ** i
        else:
            C[i][0] = 2**i + (B // (2**(i+1))) * 2**i
            C[i][1] = tmp - 2**i + (B // (2**(i+1))) * 2**i


    B = A
    for i in range(42):
        tmp = B - (B // (2**(i+1))) * 2**(i+1)
        if tmp < 2**i:
            C[i][0] -= tmp + (B // (2**(i+1))) * 2**i
            C[i][1] -= (B // (2 ** (i + 1))) * 2 ** i
        else:
            C[i][0] -= 2**i + (B // (2**(i+1))) * 2**i
            C[i][1] -= tmp - 2**i + (B // (2**(i+1))) * 2**i
    ans = 0
    for i in range(42):
        ans += C[i][1] % 2 * 2**i
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def f(x):
    res = (x+1)//2%2
    
    for i in range(1, 50):
        n = x%2**(i+1)
        
        if n>=2**i and (n-2**i)%2==0:
            res += 2**i
    
    return res

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

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

Solution (Python):
import math

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

a_p = math.ceil(A/4)
b_p = math.floor(B/4)

ans = 0

for i in range(A, 4*a_p):
    ans = ans ^ i
for j in range(b_p*4, B+1):
    ans = ans ^ j
print(ans)

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

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


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

Solution (Python):
a,b = map(int,input().split())
ans = 0
if b-a <= 4:
    for x in range(a, b+1):
        ans ^= x
else:
    s = a%4
    t = b%4
    if s == 0:
        s = 4
    for x in range(a, a+4-s):
        ans ^= x
    for x in range(b-t, b+1):
        ans ^= x
print(ans)

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

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

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

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

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

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

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



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

Solution (Python):
a,b = map(int,input().split())
A = a%4
ans1 = 0
for i in range(A):
    ans1 = ans1^(a-i-1)
B = (b+1)%4
ans2 = 0
for i in range(B):
    ans2 = ans2^(b-i)
print(ans1^ans2)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a,b = map(int, input().split())
def sub(a):
    
    ans = 0
    for i in range(a.bit_length()):
        l = pow(2,i)
        num = (a//(l*2)) * l + min(l, a%(l*2))
        num1 = a - num
        if num1%2:
            ans += l
    return ans
def sub2(a):
    ans = 0
    for i in range(a):
        ans ^= i
    return ans
ans = sub(b+1) ^ sub(a)
print(ans)

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


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

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b = na()
    if b - a < 5:
        ans = 0
        for x in range(a, b+1):
            ans ^= x
        print(ans)
        quit()
    left, right = 0, 0
    if a % 4 == 0:
        left = 0
    else:
        for i in range(a % 4, 4):
            x = (a // 4) * 4 + i
            left ^= x
    if b % 4 == 0:
        right = b
    else:
        for i in range(0, b % 4+1):
            y = (b // 4) * 4 + i
            right ^= y
    print(left^right)

if __name__ == "__main__":
    main()

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

if a==b:
    print(a)
elif a%2==0 and b%2==1:
    if ((b+1-a)//2)%2==0:
        print(0)
    else:
        print(1)
elif a%2==1 and b%2==1:
    if ((b-a)//2)%2==0:
        print(0^a)
    else:
        print(1^a)
elif a%2==0 and b%2==0:
    if ((b-a)//2)%2==0:
        print(0^b)
    else:
        print(1^b)
elif a%2==1 and b%2==0:
    if ((b-a-1)//2)%2==0:
        print(a^0^b)
    else:
        print(a^1^b)

Solution (Python):
s=0
A,B=map(int,input().split())
if abs(A-B)<30:
  for i in range(A,B+1):
    s=s^i
  print(s)
else:
  c=A//4
  L=range(A,4*(c+1))
  for i in L:
    s=s^i
  c=B//4
  L=range(4*(c-1),B+1)
  for i in L:
    s=s^i
  print(s)