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):
A,B = map(int, input().strip().split(' '))

if B-A < 4:
  answer = 0
  for i in range(A,B+1):
    answer ^= i
  print(answer)
  exit()
	
if A%2 == 0:
  head = 0
  left = A
else:
  head = A
  left = A+1

if B%2 == 0:
  tail = B
  right = B-1
else:
  tail = 0
  right = B

body = int(((right-left+1)/2)%2)
  
print(head^body^tail)

Solution (Python):





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

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

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

if a % 2 == 1:
  c = a
  a += 1

d = (b - a + 1) % 4

if d == 0:
  ans = 0
elif d == 1:
  ans = b ^ 0
elif d == 2:
  ans = 1
else:
  ans = b ^ 1
  
if c != 0:
  ans ^= c

print(ans)

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

ans = 0
for i in range(4 - a%4):
    ans ^= a + i
for j in range(b%4 + 1):
    ans ^= b - j 
print(ans)

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

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

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

ans = 0
tmp = 1
while True:
    tmp *= 2
    tmp_count0 = 0
    tmp_count1 = 0

    before_tmp = tmp//2
    loopB = (B+1) // tmp
    tmp_count0 += loopB*before_tmp
    tmp_count1 += loopB*before_tmp

    loopA = (A) // tmp
    tmp_count0 -= loopA*before_tmp
    tmp_count1 -= loopA*before_tmp

    leftB = (B+1) % tmp
    if leftB > before_tmp:
        tmp_count0 += before_tmp
        tmp_count1 += leftB-before_tmp
    else:
        tmp_count0 += leftB
    leftA = (A) % tmp
    if leftA > before_tmp:
        tmp_count0 -= before_tmp
        tmp_count1 -= leftA-before_tmp
    else:
        tmp_count0 -= leftA

    if tmp_count1 % 2 == 1:
        ans += before_tmp
    else:
        ans += 0
    
    
    if before_tmp >= B:
        break
print(ans)

Solution (Python):
import math

A,B=map(int,input().split())
p=[]

for k in range(len(bin(B))-2):
	a = (A >> k) & 1
	b = (B >> k) & 1

	if k == 0:
		if a ^ b == 1:
			p.insert(0, ((B-A+1)//2)%2)
		else:
			p.insert(0, (((B-A+1)//2)%2+a)%2)
	else:
		if a == 0 and b == 0:
			p.insert(0, 0)
		elif a == 1 and b == 1:
			p.insert(0, (A+B+1)%2)
		elif a == 1:
			p.insert(0, A % 2)
		else:
			p.insert(0, (B+1) % 2)

print(int("".join(map(str, p)), 2))

Solution (Python):
def chk(i,j):
    if (j-i+1)%4==0: return 0
    else: return 1

A,B=map(int,input().split())
a,b=A%2,B%2
if a==0 and b==0: print(chk(A,B-1)^B)
elif a==0 and b==1: print(chk(A,B))
elif a==1 and b==0: print(A^chk(A+1,B-1)^B)
elif a==1 and b==1: print(A^chk(A+1,B))

Solution (Python):


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


def f(n):
    ret = {0: n, 1: 1, 2: 1 ^ n, 3: 0}
    return ret[n % 4]


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

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

ans = 0

if A > 0:
    for i in range(A % 4):
        ans ^= (A - 1 - i)

for i in range((B + 1) % 4):
    ans ^= (B - i)

print(ans)

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

if a % 2 != 0:
    st = a
    if b % 2 != 0:
        ed = 0
        bl = (b-(a+0))//2
    else:
        ed = b
        bl = (b-(a+1))//2
else:
    st = 0
    if b % 2 != 0:
        ed = 0
        bl = (b-(a-1))//2
    else:
        ed = b
        bl = (b-(a-0))//2

print(st^ed^(1 if bl%2!=0 else 0))

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

def zo(n):
    if n % 2 == 0:
        return 0
    else:
        return 1

if A % 2 == 0 and B % 2 == 0:
    print(zo((B - A) // 2 ) ^ B)
elif A % 2 == 0 and B % 2 != 0:
    print(zo((B - A + 1) // 2))
elif A % 2 != 0 and B % 2 == 0:
    print(A ^ zo((B - A - 1) // 2) ^ B)
else:
    print(A ^ zo((B - A) // 2))

Solution (Python):
from collections import deque
B,A = list(map(int,input().split()))
Abinstr = bin(A)
Bbinstr = bin(B)
stk = deque()
if ((int((A+1)/2)-int(B/2))%2==1):
    stk.append("1")
else:
    stk.append("0")
for i in range(1,len(Abinstr)-2):
    k = 2**i-1 
    jA = (A-k)%2**(i+1)
    if B>k:
        jB = (B-1-k)%2**(i+1)
    else :
        jB=0
    if 2**i > jA and jA%2==1:
        jA = 3
    else:
        jA = 2
    
    if 2**i > jB and jB%2==1:
        jB = 1
    else:
        jB = 2
    if (jA-jB)%2==0:
        stk.appendleft("0")
    else:
        stk.appendleft("1")
print(int("".join(stk),2))

Solution (Python):
a,b=map(int,input().split())
d=b-a+1
length=1
while(2**length<=b):
    length=length+1
a_bin=format(a,'0%db' % length)
a_bin=a_bin[::-1]
answer=0
for i in range(0,length):
    a_number=int(a_bin[i])
    if a_number==0:
        index_a=a%(2**i)
    else:
        index_a=a%(2**i)+2**i
    rest=d%(2**(i+1))
    index_b=(index_a+rest-1)%(2**(i+1))
    if i==0:
        if a_number==0:
            if d%4==0 or d%4==1:
                count=0
            else:
                count=1
        else:
            if d%4==1 or d%4==2:
                count=1
            else:
                count=0
    else:
        if 0<=index_a<2**i:
            count_a=0
        else:
            if (index_a-2**i)%2==0:
                count_a=0
            else:
                count_a=1
        if 0<=index_b<2**i:
            count_b=0
        else:
            if (index_b-2**i)%2==0:
                count_b=1
            else:
                count_b=0
        count=(count_a+count_b)%2
    answer=answer+count*(2**i)
if d==1:
    print(a)
else:
    print(answer)

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



def XOR_0_to_x(x):

    
    xor = ((x+1) // 2) % 2

    if x % 2 == 0:
        return xor ^ x

    else:
        return xor



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

print(ans)

Solution (Python):




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

A, B = map(int, raw_input().split())
print '{}'.format(xor_from0(A-1) ^ xor_from0(B))

Solution (Python):
from functools import reduce

tmp=input().split(" ")
a=int(tmp[0])
b=int(tmp[1])

length = b-a+1

arr=[]
if a % 2 == 1:
    length -= 1
    arr.append(a)

if b % 2 == 0:
    length -= 1
    arr.append(b)

arr.append((length // 2 ) % 2)

print(reduce(lambda a,b:a^b, arr, 0))

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

if b == a:
  print(a)
elif (b - a) == 1:
  print(b ^ a)
else:
  if (a%2==0):
    first = a
    c = 0
  else:
    first = a + 1
    c = a
  if (b%2==1):
    last = b
    d = 0
  else:
    last = b-1
    d = b
  e = 1 if (last - first) % 4 == 1 else 0

  print(c ^ d ^ e)

Solution (Python):
A, B = map(int, input().split())
ans = 0
cnt = 0
def f(arg):
    ans = 0
    if arg < 0:
        return 0
    for pos in range(1, 41):
        
        loop = 1 << pos
        
        cnt = int((arg + 1) / loop) * (loop >> 1)
        cnt += max(0, (arg + 1) % (loop) - (loop >> 1))
        ans += cnt%2 * (loop>>1)
        
        if loop > arg:
            break
    return ans
print(f(A-1)^f(B))

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


def even_odd(x, n):
    if n == 1:
        if x % 4 == 1 or x % 4 == 2:
            return 1
        else:
            return 0

    num = (x % (2 ** n)) - 2 ** (n - 1)
    if num < 0:
        return 0
    elif num % 2 == 0:
        return 1
    else:
        return 0


s = 0
for i in range(1, 41):
    if (even_odd(B, i) + even_odd(A-1, i)) % 2 == 1:
        s += 2 ** (i - 1)
print(s)

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

Solution (Python):

import sys
INF = float("inf")


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


def solve(A: int, B: int):
    
    
    print(f(B) ^ f(A-1))

    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):
import sys
import numpy as np

reatInt = lambda: int(sys.stdin.readline())
reatIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]

a, b = reatIntN()
b += 1
a = ((a // 2) % 2) ^ ((a-1) * (a % 2))
b = ((b // 2) % 2) ^ ((b-1) * (b % 2))
ret = a ^ b
print(ret)

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

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

def cal_xor(X):
    X = X+1
    xor_sum = 0
    digit = 1
    while digit < X:
        digit *= 2
        bit_count = (X // digit) * (digit // 2)
        bit_count += max(0, (X % digit) - (digit // 2))
        
        if bit_count % 2 == 1:
            xor_sum += digit // 2
    
    return xor_sum
        

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

Solution (Python):
A, B = list(map(int, input().split()))
c = []
c.append(A % 4 // 2 ^ (B + 1) % 4 // 2)

keta = 2
while(B // keta != 0):
    if A // keta % 2 == 0:
        a = 0
    else:
        a = A % keta
    if B // keta % 2 == 0:
        b = 0
    else:
        b = B % keta
        b += 1
    c.append((b - a) % 2)
    keta = keta<<1
ans = 0

for i in range(len(c) - 1, -1, -1):
    ans = ans<<1
    ans ^= c[i]
print(ans)

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

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

assert f(2, 4) == 5, f(2, 4)
assert f(123, 456) == 435, f(123, 456)
assert f(123456789012, 123456789012) == 123456789012
a, b = map(int, input().split())
print(f(a, b))

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

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

def F0(n):
    if n%4 == 1:
        return 1
    if n%4 == 2:
        return n + 1
    if n%4 == 3:
        return 0
    if n%4 == 0:
        return n
    if n == 0:
        return 0


print(F0(A-1)^F0(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

answer = A^B
print(answer)

Solution (Python):
import math

A,B = map(int, input().split())
ans = int(0)
if B==0:
  ans = 0
else:
  N = math.floor(math.log2(B)+1)
  
  A_mod = A % 4
  B_mod = B % 4
  if A_mod < 2:
    if B_mod ==1 or B_mod == 2:
      ans += 1
  else:
    if B_mod ==3 or B_mod == 0:
      ans += 1

  for i in range(2,N+1):
    A_mod = A % (2**i)
    B_mod = B % (2**i)
    if A_mod < 2**(i-1):
      if B_mod >= 2**(i-1):
        ans += ((B_mod+1)%2)*(2**(i-1))
    else:
      if B_mod < 2**(i-1):
        ans += (A_mod%2)*(2**(i-1))
      else:
        ans += ((A_mod+B_mod+1)%2)*(2**(i-1))

print(ans)

Solution (Python):
def solve(string):
    a, b = map(int, string.split())

    def f(a):
        if a % 4 == 1:
            return 1
        if a % 4 == 2:
            return a + 1
        if a % 4 == 3 or a == 0:
            return 0
        return a

    return str(f(a - 1) ^ f(b))


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

Solution (Python):
def solve(string):
    a, b = map(int, string.split())
    if b == 0:
        return "0"
    bin_a = "{:040b}".format(a)
    bin_b = "{:040b}".format(b)
    aa = [-1 if _a == "0" else int(bin_a[i + 1:] or "0", 2) for i, _a in enumerate(bin_a)]
    bb = [-1 if _b == "0" else int(bin_b[i + 1:] or "0", 2) for i, _b in enumerate(bin_b)]
    ans = [str((bb[i] + 1 + max(0, aa[i])) % 2) for i in range(bin_b.index("1"), 40)]
    ans[-1] = str((b - a) // 2 % 2) if a % 2 == b % 2 == 0 else str(((b - a) // 2 + 1) % 2)
    return str(int("".join(ans), 2))


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

Solution (Python):
def solve(string):
    a, b = map(int, string.split())
    if b == 0:
        return "0"
    bin_a = "{:040b}".format(a)
    bin_b = "{:040b}".format(b)
    aa = [-1 if _a == "0" else int(bin_a[i + 1:] or "0", 2) for i, _a in enumerate(bin_a)]
    bb = [-1 if _b == "0" else int(bin_b[i + 1:] or "0", 2) for i, _b in enumerate(bin_b)]
    index = 0
    while True:
        if bb[index] != -1:
            break
        index += 1
    ans = []
    for i in range(index, 40):
        tmp = 0
        tmp += (bb[i] + 1) % 2 if bb[i] >= 0 else 0
        tmp += aa[i] % 2 if aa[i] > 0 else 0
        ans.append(str(tmp % 2))
    ans[-1] = str((b - a) // 2 % 2) if a % 2 == b % 2 == 0 else str(((b - a) // 2 + 1) % 2)
    return str(int("".join(ans), 2))


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

Solution (Python):
def solve(string):
    a, b = map(int, string.split())
    if b == 0:
        return "0"
    bin_a = "{:040b}".format(a)
    bin_b = "{:040b}".format(b)
    aa = [-1 if _a == "0" else int(bin_a[i + 1:] or "0", 2) for i, _a in enumerate(bin_a)]
    bb = [-1 if _b == "0" else int(bin_b[i + 1:] or "0", 2) for i, _b in enumerate(bin_b)]
    index = 0
    ans = []
    while index < 40:
        tmp = 0
        tmp += (bb[index] + 1) % 2 if bb[index] >= 0 else 0
        tmp += aa[index] % 2 if aa[index] > 0 else 0
        ans.append(str(tmp % 2))
        index += 1
    ans[-1] = str((b - a) // 2 % 2) if a % 2 == b % 2 == 0 else str(((b - a) // 2 + 1) % 2)
    return str(int("".join(ans), 2))


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

Solution (Python):
def solve(string):
    a, b = map(int, string.split())
    if b == 0:
        return "0"
    bin_a = "{:040b}".format(a)
    bin_b = "{:040b}".format(b)
    aa = [-1 if _a == "0" else int(bin_a[i + 1:] or "0", 2) for i, _a in enumerate(bin_a)]
    bb = [-1 if _b == "0" else int(bin_b[i + 1:] or "0", 2) for i, _b in enumerate(bin_b)]
    index = 0
    while True:
        if bb[index] != -1:
            break
        index += 1
    ans = []
    while index < 40:
        tmp = 0
        tmp += (bb[index] + 1) % 2 if bb[index] >= 0 else 0
        tmp += aa[index] % 2 if aa[index] > 0 else 0
        ans.append(str(tmp % 2))
        index += 1
    ans[-1] = str((b - a) // 2 % 2) if a % 2 == b % 2 == 0 else str(((b - a) // 2 + 1) % 2)
    return str(int("".join(ans), 2))


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

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



count1 = max(0, (B + 1) // 2 - (A + 1) // 2)
res = count1 % 2


if A % 2 == 1:
    res ^= A
if B % 2 == 0:
    res ^= B

print(res)

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



def count1(n, d):
    mod = n % (2 ** (d + 1))
    n >>= d + 1
    n <<= d
    return n + max(mod - 2 ** d + 1, 0)


def main():
    
    bitcounts = []
    n = B
    d = 0
    while n > 0:
        bitcounts.append(count1(B, d))
        d += 1
        n >>= 1

    n = A - 1
    d = 0
    while n > 0:
        bitcounts[d] -= count1(A - 1, d)
        d += 1
        n >>= 1

    
    r = 0
    ans = 0
    for bc in bitcounts:
        if bc % 2 == 1:
            ans += 2 ** r
        r += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
a,b = map(int,input().split())
def f(x):
    if x % 2 ==1:
        if ((x-1)//2)%2==0:
            return 1
        else:
            return 0

    else:
        if ((x-2)//2)%2 == 0:
            return x^1
        else:
            return x
print(f(a-1)^f(b))

Solution (Python):
def solve(string):
    a, b = map(int, string.split())
    if b == 0:
        return "0"
    bin_a = "{:040b}".format(a)
    bin_b = "{:040b}".format(b)
    aa = [-1 if _a == "0" else int(bin_a[i + 1:] or "0", 2) for i, _a in enumerate(bin_a)]
    bb = [-1 if _b == "0" else int(bin_b[i + 1:] or "0", 2) for i, _b in enumerate(bin_b)]
    index = 0
    while True:
        if bb[index] != -1:
            break
        index += 1
    ans = []
    while index < 40:
        if aa[index] == bb[index] == -1:
            ans.append("0")
        elif aa[index] == -1:
            ans.append(str((bb[index] + 1) % 2))
        elif bb[index] == -1:
            ans.append(str(aa[index] % 2))
        else:
            ans.append(str((bb[index] + 1 - aa[index]) % 2))
        index += 1
    ans[-1] = str((b - a) // 2 % 2) if a % 2 == b % 2 == 0 else str(((b - a) // 2 + 1) % 2)
    return str(int("".join(ans), 2))


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

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


def sum_xor(x):
    ans = 0
    x += 1
    for i in range(50):
        per = 1<<i
        cnt = (x//(2*per))*per
        cnt += max(0,(x%(2*per)-per))
        value = cnt%2
        ans += value<<i
    return ans

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

Solution (Python):
A,B = map(int, input().split())
ans = []
if A % 2 == 1:
  ans.append(A)
  s = A + 1
else:
  s = A

if B % 2 == 0:
  ans.append(B)
  g = B - 1
else:
  g = B

if (g-s+1) %  4 == 0:
  ans.append(0)
else:
  ans.append(1)

if len(ans) == 1:
  print(ans[0])
if len(ans) == 2:
  print(ans[0]^ans[1])
if len(ans) == 3:
  print(ans[0]^ans[1]^ans[2])

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

def sum_xor(i):
    i += 1
    start = i//4
    start *= 4
    ans = 0
    for e in range(start,i):
        ans ^= e
    return ans

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

Solution (Python):
import numpy as np
start,end = [int(x) for x in input().strip().split(" ")]

def get_nth_sum(n,x):
    if x < 0:
        return 0
    ret =x//(2**n)* (2**(n-1)) + max(0,x%(2**n) - 2**(n-1)+1 ) 
    return ret %2

ret = 0
for i in range(1,np.log2(end).astype(int)+3):
    ret += 2**(i-1) * ((get_nth_sum(i,end) - get_nth_sum(i,start-1))%2)
print(ret)

Solution (Python):


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

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

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

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

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

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

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

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

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

def count_bin(n, d):
    if n < 0:
        return 0
    div = (n+1)//2**(d+1)
    res = div*(2**d)
    remain = (n+1) - div*(2**(d+1))
    res += remain - 2**d if remain > 2**d else 0
    return res

ans = 0
for d in range(50):
    n_bin = count_bin(b, d) - count_bin(a-1, d)
    if n_bin%2 > 0:
        ans += 2**d
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
A, B = map(int, input().split())

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

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

Solution (Python):


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

def cum_xor(n):
    result = (n + 1) // 2 % 2
    if (n + 1) % 2 == 1: result ^= n
    return result

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

Solution (Python):
def f(x):
    v = 0
    for i in  range(1,x+1): v ^= i
    return v

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



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

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

if a == b:
  print(a)
  exit()
  
c = 0
if a % 2 == 1:
  c = a
  a += 1

if a == b:
  print(c ^ a)
  exit()

d = (b - (a - 1)) // 2
if d % 2 == 0:
  c ^= 0
else:
  c ^= 1

if b % 2 == 0:
  c ^= b

print(c)

Solution (Python):
def convert_binary(n):
    if n == 0:
        return '0'
    s = []
    while True:
        s.append(str(n % 2))
        n = int(n / 2)
        if n == 0:
            break
    return ''.join(s)[::-1]
   
def calc_xor(b1, b2):
    maxlen = max(len(b1), len(b2))
    b1 = '0' * (maxlen - len(b1)) + b1
    b2 = '0' * (maxlen - len(b2)) + b2
    s = ''
    for i in range(maxlen):
        if (int(b1[i]) + int(b2[i])) % 2 == 1:
            s += '1'
        else:
            s += '0'
    return s
   
def convert_decimal(binary):
    n = 0
    i = 0
    for b in binary[::-1]:
        n += (2 ** i) * int(b)
        i += 1
    return n
 
def calc_xor_from_zero(n):
    if (n+1) % 2 == 0:
        count_pair = int((n+1) / 2)
        if count_pair % 2 == 0:
            return '0'
        else:
            return '1'
    else:
        count_pair = int((n+1) / 2)
        if count_pair % 2 == 0:
            return calc_xor('0', convert_binary(n))
        else:
            return calc_xor('1', convert_binary(n))
    
A, B = list(map(int, input().split(' ')))
 
print(convert_decimal(calc_xor(calc_xor_from_zero(A-1), calc_xor_from_zero(B))))

Solution (Python):
N = 41
A, B = (int(x) for x in input().split())
def function(i, n):
    if i == 0:
        if n % 4 == 0 or n % 4 == 3:
            return 0
        else:
            return 1
    else:
        y, div = n, 1
        for j in range(i):
            div = div * 2

        y = n % (div * 2)
        if y < div:
            return 0
        elif y % 2 == 1:
            return 0
        else:
            return 1

def answer(A, B):
    ret = ''
    list = [0] * N
    for i in range(N):
        if (function(i, A-1) + function(i, B)) % 2 != 0:
            list[i] = 1
    for z in list:
        ret += str(z)
    ret = ret[::-1]
    return int(ret, 2)
print(answer(A, B))

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

count = B - A + 1

res = 0
ones = (count - (count % 2)) / 2
if count % 2:
    seed = A if A % 2 else B
    res = 1 ^ seed if ones % 2 else seed
else:
    res = ((A % 2)*(A ^ B ^ 1)) ^ (1 if ones % 2 else 0)

print(res)

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

count = B - A + 1

res = 0
if count % 2:
    ones = (count - 1) / 2
    seed = A if A % 2 else B
    res = 1 ^ seed if ones % 2 else seed
else:
    ones = count / 2
    if A % 2:
        res = A ^ B ^ (0 if ones % 2 else 1)
    else:
        res = 1 if ones % 2 else 0

print(res)

Solution (Python):
def calc(i):
    return [i, 1, i+1, 0][i % 4]
A, B = map(int, input().split())
if A <= 1: print(calc(B))
else: print(calc(B) ^ calc(A - 1))

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

A -= 1

XorA = 0
XorB = 0

if A % 4 == 0:
    XorA = A
elif A % 4 == 1:
    XorA = 1
elif A % 4 == 2:
    XorA = A + 1
elif A & 3 == 3:
    XorA = 0

if B & 3 == 0:
    XorB = B
elif B & 3 == 1:
    XorB = 1
elif B & 3 == 2:
    XorB = B + 1
elif B & 3 == 3:
    XorB = 0

print( XorA ^ XorB)

Solution (Python):
def solve(a, b):
    return xor(a-1) ^ xor(b)


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


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

    ans = solve(a, b)
    print(ans)


if __name__ == "__main__":
    main()

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

def xors(X):
  res = 0
  x = 2
  while True:
    if x > X:
      break
    if (X % (x*2)) >= x and (X % (x*2)) % 2 == 0:
      res = res + x
    x = x*2
  if X % 4 <= 2 and X % 4 >= 1:
    res = res + 1
  return res
print(xors(B) ^ xors(A-1))

Solution (Python):
def calc_xor(i):
	if i % 4 == 0:
		return i
	elif i % 4 == 1:
		return 1
	elif i % 4 == 2:
		return i + 1
	elif i % 4 == 3:
		return 0
	else:
		print("error")

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

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

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


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


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

print()

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

def make_base_list(N):
    base_list = [0]*40
    for i in range(40):
        if abs(N) % 2 == 0:
            base_list[i] = 0
        else:
            base_list[i] = 1
            N -= 1
        N = int(N)
        N = N // 2
    return base_list

if A % 2 == 0:
    A_base_list = [0]*40
else:
    A_base_list = make_base_list(A)

if B % 2 == 1:
    B_base_list = [0]*40
else:
    B_base_list = make_base_list(B)

xor_world = [1 if A_base_list[i]+B_base_list[i]==1 else 0 for i in range(40)]
xor_world[0] = 0

ans = 0
for i in range(40):
    ans += (2**i)*xor_world[i]

if A % 4 == 0 or A % 4 == 1:
    zero_a = 0
else:
    zero_a = 1

if B % 4 == 0 or B % 4 == 3:
    zero_b = 0
else:
    zero_b = 1
if zero_a != zero_b:
    ans += 1
print(ans)

Solution (Python):
def tobin(n):
    return bin(n)[2:][::-1]

def occur(n, i):
    if i >= len(n):
        return 0
    if n[i] == '1':
        if i == 0:
            o = 1
        else:
            o = int(n[:i][::-1], 2) + 1
    else:
        o = 0
    if i < len(n) - 1:
        o += int(n[i+1:][::-1], 2) * (2 ** i)
    return o

A, B = map(int, input().split())
A, B = tobin(A-1 if A > 0 else 0), tobin(B)
F = ""

for i in range(len(B)):
    F += str((occur(B, i) - occur(A, i)) % 2)

print(int(F[::-1], 2))

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

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

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

while True:
    if B == 0:
        break
    if 2**(k-1) <= B < 2**k:
        break
    k += 1


def sum_xor(n):
    res = []
    for i in range(k):
        if i == 0:
            res.append(1) if n % 4 == 1 or n % 4 == 2 else res.append(0)
        else:
            nmod = n % (2 ** (i + 1))
            if (2**(i+1))/2 <= nmod < 2**(i+1) and nmod % 2 == 0:
                res.append(1)
            else:
                res.append(0)
            
            
            
    res.reverse()
    return res


ax = sum_xor(A-1)
bx = sum_xor(B)

ans = []
for j in range(k):
    ans.append(1) if (ax[j] + bx[j]) % 2 == 1 else ans.append(0)

ans = "".join(map(str, ans))
print(int(ans, 2))

Solution (Python):
def main():
	n, m = map(int, input().split())
	print(f(n-1)^f(m))

def f(n: int) -> int:
	if n < 0: 
		return 0
	if n % 4 == 0:
		return n
	if n % 4 == 1:
		return 1
	if n % 4 == 2:
		return n^1
	if n % 4 == 3:
		return 0

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

def calc_xor(n):
    l = n

    if n == 0:
        d = 1
    else:
        d = int(math.log(n, 2)) + 1

    results = [0] * d
    results[0] = int(n % 4 in [1, 2])
    for i in range(2, d + 1):
        target = 2 ** i
        mod = l % target
        bit = int(mod >= target // 2 and not mod % 2)
        
        results[i - 1] = int(mod >= target // 2 and not mod % 2)

    results.reverse()
    return results


def to_int(n):
    result = 0
    for bit in n:
        result <<= 1
        result |= bit
    return result

ra = calc_xor(a)
rb = calc_xor(b)


print(to_int(ra) ^ a ^ to_int(rb))

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

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

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





def XORfromZERO(x):
    rest = x % 2
    quotient = (x + rest) / 2
    if rest == 0:
        if quotient % 2 == 0:
            return 0 ^ x
        else:
            return 1 ^ x
    else:
        if quotient % 2 == 0:
            return 0
        else:
            return 1

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

Solution (Python):


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


























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

a = func(A-1)
b = func(B)
print(a^b)

Solution (Python):
def XOR_sum(n):
    m = n + 1
    if m % 4 == 0:
        return 0
    elif m % 4 == 1:
        return n
    elif m % 4 == 2:
        return 1
    else:
        return n ^ 1

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

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

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

Solution (Python):
from collections import defaultdict
A,B = map(int,input().split())

def count(n,k):
    n = bin(n)[2:]
    n = '0'+n
    res = 0
    if n[-k-1]=='1':
        if k==0:
            res += 1
        else:
            res += (int(n[-1])+1)%2
    if k == 0:
        res = (res+int(n[-2]))%2
    return res

def f(n):
    if n < 0:
        n = 0
    d = defaultdict(lambda:0)
    for k in range(len(bin(n)[2:])):
        d[k] = count(n,k)
    return d

d_a = f(A-1)
d_b = f(B)
ans = ''
for i in range(40):
    ans = str((d_a[i]+d_b[i])%2) + ans
ans = int(ans,2)
print(ans)

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

    bit_num = calc_bit_num(B)

    xor = [0] * bit_num
    ret = 0
    for k in range(bit_num):
        period = 2 ** k
        if (num_1_until(B, period) - num_1_until(A-1, period)) % 2 == 1:
            xor[k] = 1
            ret += period

    print(ret)
    return ret

def calc_bit_num(n):

    q = n
    count = 0
    
    while q > 0:
        q = q // 2
        count += 1    

    return count

def num_1_until(num, period):

    if period == 1:
        if ((num+1) // 2) % 2 == 0:
            return 0
        else:
            return 1

    q, r = (num+1) // period, (num+1) % period

    if q % 2 == 1 and r % 2 == 1:
        return 1
    else:
        return 0


main()

Solution (Python):

"""
D - XOR World
https://atcoder.jp/contests/abc121/tasks/abc121_d

"""
import sys


def solve(A, B):
    ans = 0
    if B - A < 10:
        for i in range(A, B+1):
            ans ^= i
        return ans

    if A % 2 == 1:
        ans = A
        A += 1
    if B % 2 == 0:
        ans ^= B
        B -= 1
    pair = (B - A + 1) // 2 % 2
    ans ^= pair
    return ans


def main(args):
    A, B = map(int, input().split())
    ans = solve(A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])