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


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

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

A -= 1
if B % 4 == 1:
    B = 1
elif B % 4 == 2:
    B += 1
elif B % 4 == 3:
    B = 0
if A % 4 == 1:
    A = 1
elif A % 4 == 2:
    A += 1
elif A % 4 == 3:
    A = 0

print A ^ B

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

def getXor(n):
    ret = 0
    i = 1
    while True:
        div,mod = divmod(n,i)
        flg = i * (div // 2)
        if div % 2 == 1:
            flg += (mod + 1)
        if flg % 2 == 1:
            ret += i
        i *= 2
        if i > n:
            break
    
    return ret

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

Solution (Python):










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

def bit_i(x,i):

    y=(x+1)//(1<<i)*(1<<(i-1))
    x=x-(x+1)//(1<<i)*(1<<i)+1-(1<<(i-1))
    
    return y +max(x,0)

ANS=[]

for i in range(1,50):
    ANS.append((bit_i(B,i)-bit_i(A-1,i))%2)

print(int("".join(map(str,ANS[::-1])),2))

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

"""
r = 0
for i in range(17):
    r ^= i
    print(i, ("0000" + bin(r)[2:])[-5:])
"""

def calc(n):
    rs = []
    rs.append((n + 1) // 2 % 2)
    for i in range(1, 41):
        d = 1 << i
        x = n // d
        if x % 2 == 0:
            r = 0
        else:
            r = n % 2 ^ 1
        rs.append(r)
    return rs

b1 = calc(A - 1)
b2 = calc(B)




result = 0
for i in range(41):
    result |= (b1[i] ^ b2[i]) << i

print(result)

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


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


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

Solution (Python):
def sarch(i, n):
    ans = i // n * n // 2
    ans += max(0, i % n - n // 2)
    return ans


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

originalA = A
originalB = B
A = bin(A)[2::]
B = bin(B)[2::]
while len(A) > len(B):
    B = "0" + B
while len(A) < len(B):
    A = "0" + A
ans = []
for i in range(len(A)):
    if A[i] != B[i]:
        ans.append("1")
    else:
        ans.append("0")

ans = ""
for i in range(1, len(A) + 1):
    if (sarch(originalB + 1, 2 ** i) - sarch(originalA, 2 ** i)) % 2 != 0:

        ans = "1" + ans
    else:
        ans = "0" + ans
print(int(ans, 2))

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

if A == B:
    print(A)
    exit()
p = B-A+1
q = p //2
if A%2 == 0:
    if p%2 == 0:
        if q%2 != 0:
            print(1)
        else:
            print(0)
    else:
        if q%2 != 0:
            print(B^1)
        else:
            print(B)
else:
    if p%2 == 0:
        if q%2 != 0:
            print(A^B)
        else:
            print(A^B^1)
    else:
        if q%2 != 0:
            print(A^1)
        else:
            print(A)

Solution (Python):
def f(x):
  if x <= 0:
    return 0
  res = ((x + 1) // 2) & 1
  for l in range(1, 40):
    k = 1 << l
    if k > x:
      break
    t = x % (k << 1)
    if t < k or (t - k) & 1 == 1:
      pass
    else:
      res += k
  return res
a, b = map(int, input().split())
print(f(b) ^ f(a - 1))

Solution (Python):

def xor(b):
    if b%4==0:
        val = b
    else:
        if b%4==1:
            val=1
        else:
            if b%4==2:
                val=b+1
            else:
                val = 0
    return val


a,b = map(int,raw_input().strip().split())

val1 = xor(b)
val2 = xor(a)

print(val1^val2^a)

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

def f(a):
    res = [a, 1, a + 1, 0]
    return res[a % 4]

def xor(a, b):
    return f(b) ^ f(a-1)

print(xor(a, b))

Solution (Python):
def f(a,b):
  if a == b:
    return a
  elif a%2 == 1:
    return a^f(a+1,b)
  elif b%2 == 0:
    return f(a,b-1)^b
  else:
    return (b-a+1)//2%2

x,y = map(int,input().split())
print(f(x,y))

Solution (Python):
import sys
sys.setrecursionlimit(100000)
import heapq
input=lambda : sys.stdin.readline().rstrip('\n')

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

def f(x):
    ans=[]
    for i in range(1,42):
        if i==1:
            if x%4==1 or x%4==2:
                ans.append('1')
            else:
                ans.append('0')
        else:
            if x%(2**i)>(2**(i-1)-1) and (x%(2**i))%2==0:
                ans.append('1')
            else:
                ans.append('0')
    return ''.join(ans[::-1])


print(int(f(b),2)^int(f(a-1),2))

Solution (Python):
def func(a):
	val1=0
	if(a%4==0):
		val1=a
	elif(a%4==1):
		val1=1
	elif(a%4==2):
		val1=a+1
	elif(a%4==3):
		val1=0
	return val1
a,b=map(int,input().split())

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

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

ans = 0
for i in range(A,((A+4)//4)*4):
    ans ^= i
for i in range(((B-4)//4)*4,B+1):
    ans ^= i
print(ans)

Solution (Python):
def func(k):
    ans = 1 - (k-1)//2%2
    for d in range(1, 45):
        if (k & (1<<d)) and (k & 1 == 0):
            ans += 1<<d
    return ans

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

fA = func(max(0, A-1))
fB = func(B)
print(fA ^ fB)

Solution (Python):
a,b=map(int,input().split())
ans=0
while a<=b and a%2==1:
  ans^=a
  a+=1
while b>=a and b%2==0:
  ans^=b
  b-=1
if a<=b:
  dist=(b-a+1)/2
  if dist % 2 ==1:
    ans^=1
print(ans)

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

f_1_A = 0
for i in range((A // 4) * 4, A):
  f_1_A ^= i

f_1_B = 0
for i in range((B // 4) * 4, B+1):
  f_1_B ^= i

print(f_1_A ^ f_1_B)

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

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

Solution (Python):
def solve(m,n):
	l = []
	if m%2 == 0:
		l = [n,1,n^1,0]
	else:
		l = [m,m^n,m-1,(m-1)^n]
	return l[(n-m)%4]


a,b = map(int, raw_input().split())
print solve(a,b)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

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

L = 41

A, B = reads()
def solve(n):
  ans = 0
  for i in range(L+1):
    q, r = divmod(n, 2 ** (i + 1))
    ans |= ((q * (2 ** i) + max(0, r - 2 ** i)) & 1) << i
  return ans
print(solve(A) ^ solve(B+1))

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

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

ruiA1 = ruisekiXOR(A - 1)
ruiB = ruisekiXOR(B)

print(ruiA1 ^ ruiB)

Solution (Python):



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

def f(x):
    if x == 0 or x==3:
        return 0
    elif x== 1:
        return 1
    elif x == 2:
        return 3
    y=x
    c=0
    while(y > 0):
        c+=1
        y=y//2
    
    return ((x+1)%2)*(2**(c-1)) + f(x-2**(c-1))

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

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

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

ans = 0
for i in range(50):
    cnt = 0
    num1 = A
    cnt -= num1 / (2 ** (i + 1)) * (2 ** i)
    cnt -= max(0, num1 % (2 ** (i + 1)) - 2 ** i)
    num1 = B + 1
    cnt += num1 / (2 ** (i + 1)) * (2 ** i)
    cnt += max(0, num1 % (2 ** (i + 1)) - 2 ** i)
    if cnt % 2:
        ans += 2 ** i
print ans

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

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

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


def f(a, b):
    return g(b) ^ g(a - 1)


def main():
    a, b = (int(z) for z in input().split())
    print(f(a, b))


if __name__ == "__main__":
    main()

Solution (Python):

def g(n):
    acc = 0
    if (n % 4) >= 2:
        acc ^= 1
    for k in range(1, 60):
        q = n % (2 ** (k + 1))
        if q > 2 ** k and q % 2 == 1:
            acc ^= 2 ** k
    return acc

def main():
    a, b = map(int, input().split())
    print(g(b + 1) ^ g(a))

if __name__ == '__main__':
    main()

Solution (Python):

import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 
a=nCast(input().split());


def xor(n):
    if n==0:
        return 0
    if n%4==1:
        return 1
    if n%4==2:
        return n+1
    if n%4==3:
        return 0
    if n%4==0:
        return n
 
 
def func():
    return xor(a[1])^xor(a[0]-1)
print(func())

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

def f(a):
  res = [a, 1, a + 1, 0]
  return res[a % 4]

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

Solution (Python):
def xxx(n):
    ret = int(n % 4 in (1, 2))
    if n % 2 == 1:
        return ret
    for d in range(1, 40):
        if (n >> d) % 2 == 1:
            ret += 1 << d
    return ret


a, b = map(int, input().split())
if a == 0:
    a += 1
print(xxx(a - 1) ^ xxx(b))

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

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

L = 41

A, B = reads()
def solve(n):
  ans = 0
  for i in range(L+1):
    q, r = divmod(n, 2 ** (i + 1))
    ans |= ((q * (2 ** i) + max(0, r - 2 ** i)) & 1) << i
  return ans
print(solve(A) ^ solve(B+1))

Solution (Python):
from math import log
a,b = map(int,input().split())

res = 0
while b % 4 != 3:
    res ^= b
    b -= 1
while (a - 1) % 4 != 3:
    res ^= a - 1
    a -= 1
print(res)

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

def f(X):
  if X<0:
    return 0
  a = 0
  for b in range(60):
    if b==0 and ((X+1)/2%2==1) or b>0 and (X>>b&1)==1 and (X&1)==0:
      a |= 1<<b
  return a

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

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
A,B=map(int,input().split())
print(g(A-1)^g(B))

Solution (Python):

"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """ dict() -> new empty dictionary """

    def items(self):
        """ D.items() -> a set-like object providing a view on D's items """
        return dict.iteritems(self)

    def keys(self):
        """ D.keys() -> a set-like object providing a view on D's keys """
        return dict.iterkeys(self)

    def values(self):
        """ D.values() -> an object providing a view on D's values """
        return dict.itervalues(self)


def gcd(x, y):
    """ greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


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

    def solve(m, n):
        if m % 2 == 0:
            res = [n, 1, n ^ 1, 0]
        else:
            res = [m, m ^ n, m - 1, (m - 1) ^ n]
        return res[(n - m) % 4]

    print(solve(a, b))


if __name__ == '__main__':
    main()

Solution (Python):
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

g = lambda x: [x, 1, x + 1, 0][x % 4]
l, r = mi()
ans = g(r) ^ (g(l - 1) if l else 0)
print(ans)

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

a, b = map(int, raw_input().strip().split())
ans = xor(b) ^ xor(a) ^ a

print ans

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

a, b = na()

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

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