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):
import math
A,B=map(int,input().split())
x=0
if A%2==0:
    if(B%2==0):
        if((B-A)/2 %2 == 0 ):
            print(B)
        else:
            print(1^B)
    else:
        if(((B+1) - A)/2 %2 == 0):
            print(0)
        else:
            print(1)
else:
    if(B%2==0):
        if((B-(A+1))/2 %2 ==0):
            print(A^B)
        else:
            print(A^B^1)
    else:
        if((B-A)/2 %2 == 0):
            print(A)
        else:
            print(A^1)

Solution (Python):
def find(i, a):
    if i == 0:
        return (a + 1) // 2
    else:
        tmp = max(a % 2**(i + 1) - 2**i + 1, 0)
        return (a // 2**(i + 1)) * 2**i + tmp


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


A, B = inpl()
ans = 0

for i in range(0, 41):
    if A == 0:
        a2 = 0
    else:
        a2 = find(i, A - 1)
    b2 = find(i, B)
    if (b2 - a2) % 2 == 1:
        ans += 2**i
    

print(ans)

Solution (Python):
a,b = (int(i) for i in input().split())
def f(n):
    if n%2: return ((n+1)//2)%2
    else: return (((n+1)//2)%2)^n
print(f(a-1)^f(b))

Solution (Python):
""" AtCoder """

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

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

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

def calc(n):
    mod = n % 4
    if mod == 0:
        return n
    elif mod == 1:
        return n ^ (n-1) 
    elif mod == 2:
        return n ^ 1
    elif mod == 3:
        return 0
a = calc(A - 1)
b = calc(B)

print(a ^ b)

Solution (Python):
import math

a, b = [int(i) for i in input().split(" ")]

def n_one(i, p):
    if i < 0:
        return 0
    a = 2**(p + 1)
    c = i // a
    m = i % a
    return c * (a // 2) + max(0, m + 1 - a // 2)

n = int(math.log2(max(1, b))) + 1

s = 0
for p in range(0, n):
    c = n_one(b, p) - n_one(a - 1, p)
    s += (c % 2) * 2**p
print(s)

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

Solution (Python):
a, b = map(int, input().split())
def sxor(n):
    p = 0
    res = 0
    xor = (n&1)^((n>>1)&1)
    res |= xor
    p += 1
    if n&1 == 0:
        res |= n
    return res
if a == b:
    print(a)
elif a == 0:
    print(sxor(b))
else:
    print(sxor(a-1)^sxor(b))

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

def func(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x+1
    else:
        return 0
        
print(func(b) ^ func(a) ^ a)

Solution (Python):
A, B = map(int, input().split())
def func(x):
  a = (x+1) // 2
  b = a % 2
  c = x if (x+1) % 2 == 1 else 0
  return b^c
print(func(A-1)^func(B))

Solution (Python):
def loop(a,b,n):
    add = 0
    if(n==0):
        return 0
    if(a<2**n and b<2**n):
        return loop(a,b,n-1)
    if(a>=2**n):
        add = (add+(2**(n+1)-a))%2
        a-=2**n
    if(b>=2**n):
        add = (add+(b-2**n+1))%2
        b-=2**n
    return add*2**n+loop(a,b,n-1)

A,B = [int(x) for x in input().split()]
last_num = 0
if(((B-A+1)%4 == 1 and A%2 == 1) or (B-A+1)%4 == 2 or ((B-A+1)%4 == 3 and A%2 == 0)):
    last_num = 1
print(loop(A,B,41)+last_num)

Solution (Python):
a,b = map(int,input().split())
c = []
if a % 4 != 0:
    c += list(range(a,a+4-a%4))
c += list(range(b-b%4,b+1))

d = 0
for i in c:
    d = d ^ i
print(d)

Solution (Python):
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

A,B = ints_raw()
ans =0
exk = 0
start_eve = A if A %2 ==0 else A+1
end_odd = B if B%2 ==1 else B-1

dd = int((end_odd-start_eve+1)/2) % 2

print (0 if start_eve == A else A)^dd^(0 if end_odd == B else B)

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


def f(num):
    if num % 4 == 0:
        return num
    if num % 4 == 1:
        return 1

    if num % 4 == 2:
        return num + 1
    return 0

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

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

def calc(a):
    cnt = (a + 1) / 2
    ans = int(cnt  % 2)
    if a % 2 == 0:
        ans ^= a
        
    return ans
    
print(calc(B)^calc(A-1))

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

def calc(i):
  if (i+1)%2 ==0:
    return ((i+1)//2%2)
  else:
    return ((i+1)//2%2)^i


if a<1:
  print(calc(b))
else:
  print(calc(a-1)^calc(b))

Solution (Python):
a, b = (int(i) for i in input().split())
def f0(x):
    xx = (x + 1) % 4
    if xx == 0:
        return 0
    elif xx == 1:
        return x
    elif xx == 2:
        return 1
    else:
        return x^1
a = f0(a-1)
b = f0(b)
print(a^b)

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

def hoge(N):
  tmp = N//2
  if N%2 == 1:
    tmp+=1
    last=0
  else:
    last=N
  if tmp%2 == 1:
    return last+1
  else:
    return last

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

Solution (Python):
import sys

if __name__ == "__main__":
    para_list = list(map(int, input().split()))
    A = para_list[0]
    B = para_list[1]

    length = B-A+1
    if length == 1:
        print(A)
    elif A%2 == 0:
        if length%2 == 0:
            if length%4 ==0:
                print(0)
            else:
                print(1)
        else:
            if (length-1)%4 == 0:
                print(B)
            else:
                print(1^B)
    else:
        length -= 1
        if length%2 == 0:
            if length%4 ==0:
                print(A)
            else:
                print(A^1)
        else:
            if (length-1)%4 == 0:
                print(A^B)
            else:
                print(A^1^B)

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

def calc(i):
  ans = [0 for _ in range(40)]
  i += 1
  for j in range(1,41):
    
    loop = 2**j
    c = (i//loop)*(loop/2)
    c += max(0,(i%loop)-(loop/2))
    if c%2 == 1:
      ans[-j]+=1
  ans = int(''.join(str(_) for _ in ans),2)
  return ans

if a<1:
  print(calc(b))
else:
  print(calc(a-1)^calc(b))

Solution (Python):
def xorsum(x):
    if x % 4 == 0:
        return(x)
    if x % 4 == 1:
        return(1)
    if x % 4 == 2:
        return(x+1)
    if x % 4 == 3:
        return(0)
    
A, B = map(int,input().split())

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

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

if __name__ == '__main__':

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

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

Solution (Python):
a, b = map(int, input().split())
A = str(bin(a))[2:]
B = str(bin(b))[2:]
if A[-1] == '0':
    if (b-a+1)%2 == 0:
        mae = '0'
    else:
        if a <= 1:
            c = '0'
        else:
            c = A[:-1]
        mae = str(bin(int(c, 2)+int((b-a)/2)))[2:]
    if (b-a+1)%4 == 0 or (b-a+1)%4 == 1:
        print(int(mae+'0', 2))
    else:
        print(int(mae+'1', 2))
else:
    if (b-a+1)%2 == 0:
        if a <= 1:
            c = '0'
        else:
            c = A[:-1]
        if b <= 1:
            d = '0'
        else:
            d = B[:-1]

        mae = str(bin(int(c, 2)^int(d, 2)))[2:]
    else:
        mae = A[:-1]
    if (b-a+1)%4 == 0 or (b-a+1)%4 == 3:
        print(int(mae+'0', 2))
    else:
        print(int(mae+'1', 2))

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==1:
        print(A-int(((B-A)/2)%2))
    else:
        print(A^B+int(((B-A-1)/2)%2))

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

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

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

def f(d):
    if 1 == d % 2:
        n1 = int(d / 2) + 1
        return 1 if 1 == n1 % 2 else 0
    else:
        n1 = d / 2
        return d + 1 if 1 == n1 % 2 else d

ans = f(a-1) ^ f(b) if 0 != a else f(b)
print(ans)

Solution (Python):
a,b=map(int,input().split())
def g(n):
  return int((n+1)/2 %2)

def f(n):
  if n%2==1:
    return g(n)
  else:
    return g(n+1)^(n+1)
print((f(b)^f(a-1)))

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

if A > 0:
    if (A - 1) % 4 == 0:
        part1 = A - 1
    elif (A - 1) % 4 == 1:
        part1 = 1
    elif (A - 1) % 4 == 2:
        part1 = A
    else:
        part1 = 0
if B > 0:
    if B % 4 == 0:
        part2 = B
    elif B % 4 == 1:
        part2 = 1
    elif B % 4 == 2:
        part2 = B + 1
    else:
        part2 = 0

print(part1 ^ part2)

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
  elif n%4==3:
    return 0
print((f(b)^f(a-1)))

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

if a == b:
    print(a)
elif b - a == 1:
    print(a^b)
elif b - a == 2:
    print(a^(a+1)^(b))
else:
    if a % 2 == 0:
        a_num = 0
        a_index = a
    else:
        a_num = a
        a_index = a+1
    if b % 2 == 1:
        b_num = 0
        b_index = b
    else:
        b_num = b
        b_index = b-1
    if ((b_index - a_index + 1) // 2) % 2 == 1:
        r = 1
    else:
        r = 0
    print(a_num ^ b_num ^ r)

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(a - 1) ^ f(b))

Solution (Python):


"""
Created on 2019/3/9
Solved on 2019/3/9
@author: shinjisu
"""






def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**12


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def prob_D_v1():
    A, B = getIntList()
    dmp((A, B))
    res = A
    for i in range(A+1, B+1):
        res = res ^ i
    dmp(res)
    return res


def prob_D_v2():
    A, B = getIntList()
    dmp((A, B))
    if (B-A) % 2 == 0:
        res = (A^B) ^ (A+B)//2
        count = (B-A)//2 
    else:
        res = (A^B)
        count = (B-A)//2
    dmp((res,count))
    if count % 2 == 0:
        res = res ^ res
    dmp(res)
    return res


def prob_D_v3():
    A, B = getIntList()
    dmp((A, B))
    pairCount = (B-A+1)//2
    dmp(pairCount, 'pairCount')
    xorAB = A ^ B
    dmp(xorAB, 'xorAB')
    res = xorAB
    if pairCount % 2 == 0:
        res = res ^ xorAB  
    dmp(res)
    if (B-A+1) % 2 == 1:
        res = res ^ (A+B)//2
    dmp(res)
    return res


def answer(a, b):
    ans = 0
    if debug:
        for i in range(a, b+1):
            ans = ans ^ i
        dmp(ans, 'ans')
    return ans


def prob_D():
    A, B = getIntList()
    dmp((A, B))
    count = B-A+1
    mod4 = count % 4
    dmp((count, mod4), 'count, mod4')
    if mod4 == 0:
        if A % 2 == 0:
            res = 0
        else:
            res = A ^ 1 ^ B
    elif mod4 == 1:
        if A % 2 == 0:
            res = B
        else:
            res = A
    elif mod4 == 2:
        if A % 2 == 0:
            res = 1
        else:
            res = A ^ B
    else:  
        if A % 2 == 0:
            res = 1 ^ B
        else:
            res = A ^ 1
    dmp(res)
    
    return res


debug = False  
ans = prob_D()
print(ans)

Solution (Python):
import sys
import bisect
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())

A, B = tuple(li())

def F(num):
    if num == 0:
        return 0
    
    a = (num + 1) // 2
    ret = 0 if a % 2 == 0 else 1
    ret = ret ^ num if num % 2 == 0 else ret
    return ret
res = F(A - 1) ^ F(B)
print(res)

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

ans = 0
for i in [a-1,b]:
    if i % 2 == 1:
        if ((i+1) // 2) % 2 == 0:
            num_1 = 0
        else:
            num_1 = 1
    else:
        if (i // 2) % 2 == 0:
            num_1 = 0
        else:
            num_1 = 1
        num_1 = i ^ num_1
    ans = ans ^ num_1
print(ans)

Solution (Python):
a, b= map(int, input().split())
if a % 2 ==0:
    start = a
    remain_before = 0
else:
    start = a+1
    remain_before = a

if b % 2 ==0:
    end = b-1
    remain_after = b
else:
    end = b
    remain_after = 0

if ((end+1-start) /2) %2 == 0:
    num = 0
else:
    num = 1

print(remain_before ^ num ^ remain_after)

Solution (Python):
import numpy as np
a, b= map(int, input().split())
if a % 2 ==0:
    start = a
    remain_before = 0
else:
    start = a+1
    remain_before = a

if b % 2 ==0:
    end = b-1
    remain_after = b
else:
    end = b
    remain_after = 0

if ((end+1-start) /2) %2 == 0:
    num = 0
else:
    num = 1

print(remain_before ^ num ^ remain_after)

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(A-1)^f(B))

Solution (Python):
a, b = map(int, input().split())
cnt = b - a + 1

def xor_chain(n):
	return n // 2 % 2

ans = 0
if a % 2 == 0:
	if b % 2 == 0:
		ans = xor_chain(cnt) ^ b
	else:
		ans = xor_chain(cnt)
else:
	if b % 2 == 0:
		ans = a ^ xor_chain(cnt - 2) ^ b
	else:
		ans = a ^ xor_chain(cnt)
print(ans)

Solution (Python):
def sarch(N):
    if N / 2 % 2 == 0:
        return 0
    else:
        return 1

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

B += 1
if A % 2 != 0:
    A -= 1
    A = sarch(A) ^ A
else:
    A = sarch(A)

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

print(A ^ B)

Solution (Python):
start_A, end_B = map(long, raw_input().split())

result = 0
if start_A == end_B:
  result = start_A
else:
  num_count = end_B - start_A + 1
  if start_A % 2 == 0:
    num_pair = num_count // 2
    if num_count % 2 == 0:
      result = num_pair % 2
    else:
      result = (num_pair % 2) ^ end_B
  else:
    num_pair = (num_count - 1) // 2
    if (num_count - 1) % 2 == 0:
      result = start_A ^ (num_pair % 2)       
    else:
      result = start_A ^ (num_pair % 2) ^ end_B

print result

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

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

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

Solution (Python):
def f(x):
    x+=1
    ans=0
    for i in range(50):
        loop=1<<(i+1)
        cnt=(x//loop)*(loop//2)
        cnt+=max(0,x%loop-loop//2)
        if cnt%2==1:
            ans+=1<<i
    return ans 
a,b=map(int,input().split())
print(f(a-1)^f(b))

Solution (Python):
def count1s(n,i):
    """２進数のi桁目に、n以下で何個1があるか"""
    rn = n % (2**i)
    dn = n // (2**i)
    if rn < (2**(i-1)-1):
        cnt = dn*(2**(i-1))
    else:
        cnt = dn*(2**(i-1)) + rn - (2**(i-1)-1)
    return cnt

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

s = ''
for i in range(41):
    cai = count1s(a-1,i+1)
    cbi = count1s(b,i+1)
    if (cbi - cai) % 2 == 0:
        s = '0' + s
    else:
        s = '1' + s
ans = int(''.join(s), 2)

print(ans)

Solution (Python):


import math


def f(x):
    if x <= 0:
        return 0
    x += 1
    digit = math.ceil(math.log2(x)) + 1

    ret = 0
    for d in range(digit):
        loop = 1 << (d + 1)
        count = (x // loop) * (loop // 2)
        count += max(0, x % loop - loop // 2)

        if count % 2 == 1:
            ret += 1 << d
    return ret



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

Solution (Python):
def F0_N(N):
  if N % 4 == 0:
  	return N
  elif N % 4 == 1:
    return 1
  elif N % 4 == 2:
     return N + 1
  elif N % 4 == 3:
     return 0

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

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

Solution (Python):
def f(n):
    x = n // 2

    if n % 2 == 0:
        if x % 2 == 0:
            return 0 ^ n
        else:
            return 1 ^ n

    else:
        x += 1
        if x % 2 == 0:
            return 0
        else:
            return 1


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

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

Solution (Python):
import sys

DBG =  not True

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

a,b = map(int, input().split())
ret = g(b)^g(a-1)
if DBG:
    print('b {} a-1 {} gb {} ga1 {} ret {}'.format(
                              b,a-1,g(b),g(a-1),ret))
print(ret)

Solution (Python):
import math

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


def main():
    
    pair = math.floor((B - A) / 2)

    if A % 2 == 0:
        pair = math.ceil((B - A) / 2)

        if B % 2 == 1:
            print(pair % 2)
        else:
            print(pair % 2 ^ B)

    else:
        if B % 2 == 1:
            print(A ^ pair % 2)
        else:
            print(A ^ pair % 2 ^ B)

    return


main()

Solution (Python):
import math


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

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 % 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 = [int(i) for i in input().split()]
def f(n):
    return [n, 1, n + 1, 0][n % 4]
print(f(A - 1) ^ f(B))

Solution (Python):
A, B = [int(i) for i in input().split()]
def f(n):
    return [n, (n - 1) ^ n, (n - 2) ^ (n - 1) ^ n, 0][n % 4]
print(f(A - 1) ^ f(B))

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

def f(A):
    return (((A + 1) // 2) % 2) ^ (((A + 1) % 2) * A)

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

Solution (Python):


def solve(a):
    if a <= 1:
        return a
    if a % 2 == 0:
        return a ^ ((a // 2) % 2)
    return ((a + 1) // 2) % 2


def main():
    a, b = map(int, input().split())
    if a > 0:
        a -= 1
    print(solve(a) ^ solve(b))


if __name__ == '__main__':
    main()

Solution (Python):
def oddsolve(x):
    return int((x+1) / 2 % 2)
def solve(x):
    if x % 2 ==0:
        return oddsolve(x+1)^(x+1)
    else:
        return oddsolve(x)

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

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

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

def f(x):
  if(x%4 == 0):
    return x
  elif(x%4 == 1):
    return x^(x-1)
  elif(x%4 == 2):
    return x^(x-1)^(x-2)
  elif(x%4 == 3):
    return 0
print(f(B) ^ f(A-1))

Solution (Python):
A, B = [int(_) for _ in input().split()]
a = max(0, ((A - 1) // 4) * 4)
b = max(A, (B // 4) * 4)
ans = 0

for i in list(range(b, B + 1)) + list(range(a, A)):
    ans ^= i

print(ans)

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

a = []
a = input().split(" ")
n = int(a[0])
m = int(a[1])
x = check(n-1) ^ check(m)
print(x)

Solution (Python):
a,b=map(int,input().split());print(a%2*~-a^~-b%2*b^(a^-b)%4//2)

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

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

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

Solution (Python):
a, b = map(int, input().split())
ans = 0
for i in range(4*(a//4), a):
  ans = ans^i
for i in range(4*(b//4),b+1):
  ans = ans^i

print(ans)

Solution (Python):
def calculate(A):
  c=(int((A+1)/2))%2
  if A%2==0:
    c=c^A
  return c

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

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

xor = [0, 1, 3]
if A == 0:
    left = 0
elif A - 1 < 3:
    left = xor[A - 1]
else:
    amari = ((A - 1) - 3) % 4
    if amari == 0:
        left = 0
    elif amari == 1:
        left = A - 1
    elif amari == 2:
        left = 1
    elif amari == 3:
        left = (A - 1) ^ 1
    
if B == 0:
    right = 0
elif B < 3:
    right = xor[B]
else:
    amari = (B - 3) % 4
    if amari == 0:
        right = 0
    elif amari == 1:
        right = B
    elif amari == 2:
        right = 1
    elif amari == 3:
        right = B ^ 1

print(left ^ right)

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


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


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):


"""
参考：https://img.atcoder.jp/abc121/editorial.pdf
　　　https://www.youtube.com/watch?v=igfVeTsGeYw
・2周期じゃなくて4周期で分ける版
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B=MAP()

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


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

Solution (Python):
from functools import reduce

A, B = map(int, input().split())
if A == B:
    result = A
else:
    result_top = reduce(lambda acc, n: acc ^ n, range(A, (int(A/4)+1) * 4))
    result_tail = reduce(lambda acc, n: acc ^ n, range(int(B/4) * 4, B + 1))
    result = result_top ^ result_tail

print("{}".format(result))

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B):
    def f(n):
        return ((n + 1) // 2) % 2 + (n if n % 2 == 0 else 0)

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


def main():
    A, B = read_int_n()
    
    print(slv(A, B))


if __name__ == '__main__':
    main()

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

Solution (Python):
















A, B = map(int, input().split())
def xor(x):
    mod = x % 4
    if mod == 0:
        return x
    elif mod == 1:
        return 1
    elif mod == 2:
        return x ^ 1
    elif mod == 3:
        return 0
print(xor(A-1) ^ xor(B))

Solution (Python):

import numpy as np
a, b = map(int, input().split())
a-=1
ans = [a,1,a+1,0][a%4]^[b,1,b+1,0][b%4]
print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B):
    def f(n):
        ans = 0
        n += 1
        for i in range(41):
            c = 1 << (i+1)
            d = (n // c) * (c // 2)
            d += max(0, n % c - c // 2)
            if d % 2 == 1:
                ans += 1 << i

        return ans

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


def main():
    A, B = read_int_n()
    
    print(slv(A, B))


if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np
import sys

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

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

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

Solution (Python):


"""
参考：https://img.atcoder.jp/abc121/editorial.pdf
　　　https://www.youtube.com/watch?v=igfVeTsGeYw
・公式解
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B=MAP()

def calc(n):
    
    
    res=(n+1)//2%2
    
    if n%2==0:
        res^=n
    return res

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

Solution (Python):
def f(x):
    x += 1
    ans = 0
    for i in range(50):
        loop = 1 << (i + 1)
        cnt = (x // loop) * (loop // 2)
        cnt += max(0, (x % loop) - (loop // 2))
        if cnt % 2:
            ans += 1 << i
    return ans


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

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


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

Solution (Python):
a,b=map(int,input().split())
xa=0
if a==b:
    print(a)
elif b-a<4:
    x=0
    for i in range(a,b+1):
        x^=i
    print(x)
else:
    if a%4:
        for i in range(4-a%4):
            xa^=a+i
    xb=0
    if b%4 != 3:
        for i in reversed(range(b%4+1)):
            xb^=b-i
    print(xa^xb)

Solution (Python):
n,m=map(int,input().split())
print(((n&1)*n)^(((m&1)^1)*m)^((n^m)&1)^(((n^m)&2)>>1))

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

def XOR(A):
    
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)

Solution (Python):
N,M = map(int,input().split())
def xor_sum(N):
    N+=1
    value = 0
    value += (N//2)%2 
    for i in range(1,40):
        
        cnt = max(0,N%(2**(i+1))-2**i) 
        value += (cnt%2) * 2**i
    return value


print(xor_sum(M)^xor_sum(N-1))

Solution (Python):
import sys
 

A,B = sys.stdin.readline().strip().split()
A = int(A)
B = int(B)

def g(x):
    if(x%4==0):
        return x
    else:
        y=int(x/4)*4
        int_y = y
        for i in range(x%4):
            y = y^(int_y+i+1)
        return y

if(A>0):
    a = g(A-1)
else:
    a = g(A)
b = g(B)

ans = a^b
print(ans)