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

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

if b == 0:
    print(0)
    exit()

m = 0
while 2**m <= b:
    m += 1
m -= 1

ans = 0
for i in range(m+1):
    qb, rb = divmod(b, 2**(i+1))
    if 0 <= rb < 2**i:
        fb = (2**i)*qb
    else:
        fb = (2**i)*qb + rb-2**i+1
    qa, ra = divmod(max(a-1, 0), 2**(i+1))
    if 0 <= ra < 2**i:
        fa = (2**i)*qa
    else:
        fa = (2**i)*qa + ra-2**i+1
    t = fb - fa
    if t%2 == 1:
        ans += 2**i

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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

A, B = MAP()

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

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

Solution (Python):
A,B = map(int,input().split())
def c(n):
    m = n//4*4
    r = 0
    for i in range(m,n+1):
        r ^= i
    return r
print(c(B) ^ c(A-1))

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

def XORACC(a):
    if a % 4 == 0:
        return a
    elif a % 4 == 1:
        return 1
    elif a % 4 == 2:
        return a + 1
    else:
        return 0

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

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

def solve():
    a,b = map(int,input().split())
    print(f(a-1)^f(b))
if __name__=='__main__':
    solve()

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

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

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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 LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def s(n):
        if n&3 == 3:
            return 0
        m = 4*(n//4)
        res = 0
        for i in range(m,n+1):
            res ^= i
        return res
    a,b = LI()
    if a == 0:
        print(s(b))
    else:
        print(s(b)^s(a-1))
    return


if __name__ == "__main__":
    solve()

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

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

def check(n):
    digits = [0] * 45
    for i in range(45):
        if i >= 1:
            am = n % (2 ** (i+1))
            if am > 2 ** i  and am % 2:
                am = 1
            else:
                am = 0
            sh = 0
        else:
            sh = n // 2
            am = 0
        digits[i] = (sh + am) % 2
    return digits
        
a = check(A)
b = check(B+1)
ans = 0
for i in range(45):
    ans += ((a[i] + b[i]) % 2) * (2 ** i)

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

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


def solve_odd(x):
    if (x + 1) % 4 == 0:
        return 1
    else:
        return 0


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


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

Solution (Python):
def f(n,i):
    if n==0:return 0
    le = (n+1)//2**i
    return le*2**(i-1) + max(0, n+1-le*2**i-2**(i-1))


a,b = map(int,input().split())
l = len(bin(b))-2
ans = 0
for i in range(1,l+1):
    ca = f(a-1,i)
    cb = f(b,i)
    ans = ans | (ca+cb)%2 * 2**(i-1)
print(ans)

Solution (Python):
def f(a):
    if a < 0:
        return 0
    if a % 2:
        return (a // 2 + 1) % 2
    return a // 2 % 2 + a

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

if __name__ == '__main__':
    main()

Solution (Python):
from math import log2

def main():
    a, b = map(int, input().split())
    if a == b:
        print(a)
        return
    if b == 0:
        print(0)
        return
    d = b - a + 1
    x = (d // 2 + (d % 2) * (a % 2)) % 2
    for i in range(1, int(log2(b)) + 1):
        k = 0
        p = 2**i
        q = 2 * p
        pa, qa = a % p, a % q
        pb, qb = b % p, b % q
        if a % q >= p:
            k += q - qa
        if b % q >= p:
            k += qb - p + 1
        x += (k % 2) * p
    print(x)

if __name__ == '__main__':
    main()

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==2:
    return 1^X
  elif X%4==3:
    return 0
if A==0:
  ans=f(B)
else:
  ans=f(A-1)^f(B)
print(ans)

Solution (Python):
a,b = [int(i) for i in input().split()]
if (a-1)%4 == 0:
  s_a = a-1
elif (a-1)%4 == 1:
  s_a = 1
elif (a-1)%4 == 2:
  s_a = (a-1)^1
else:
  s_a = 0
  
if b%4 == 0:
  s_b = b
elif b%4 == 1:
  s_b = 1
elif b%4 == 2:
  s_b = b^1
else:
  s_b = 0
  
print(s_a^s_b)

Solution (Python):
def num(x, i):
    basecnt = (x+1)//(2**(i+1))
    base = basecnt*(2**i)
    
    
    nokori = x - basecnt*(2**(i+1)) + 1
    
    plus = nokori - 2**i
    if plus > 0:
        return base+plus
    else:
        return base
def main():
    A, B = map(int, input().split())
    maxketa = len(bin(B)[2:])

    ans = 0
    for i in range(maxketa):
        Anum = num(A-1, i)
        Bnum = num(B, i)
        one = Bnum - Anum
        if one%2!=0:
            ans += 2**i
    print(ans)
main()

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

def main():
    def count1(d, i):
        i2 = 2 ** i
        ret = (d // i2) * (i2 // 2)
        d -= 2 * ret
        if d >= i2 // 2:
            ret += d - (i2 // 2) + 1
        return ret

    A, B = [int(x) for x in input().strip().split()]
    ans = 0
    for i in range(40):
        ans += ((count1(B, i+1) - count1(A-1, i+1)) % 2) * 2 ** i
    
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

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

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





ans=0
for i in range(40):
  now=0
  aone=False
  bone=False
  if A>>i&1==1:
    aone=True
  if B>>i&1==1:
    bone=True
  amod=(A)%(2**i)
  bmod=(B)%(2**i)
  
  left=(A//(2**i))*(2**i)+amod+1
  right=(B//(2**i))*(2**i)+bmod+1
  base=right-left+1
  
  if aone:
    now+=2**i-amod
    base-=2**i-amod
  if bone:
    now+=bmod+1
    base-=bmod+1
  if amod!=bmod:
    now+=(base//(2**i))*2
  now+=((base//(2**i))//2)*2**i
  if now%2==1:
    ans+=2**i
  
  
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline




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





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

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

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

if A%2==1 and B%2==1:
  tmp=(B-A)/2%2
  if tmp%2==1:
    print(A-1)
  else:
    print(A)
elif A%2==1 and B%2==0:
  A2=bin(A)[2:]
  B2=bin(B)[2:]
  A2="0"*(len(B2)-len(A2))+A2
  C="0"*len(A2)
  for i in range(len(A2)):
    if A2[i:i+1]!=B2[i:i+1]:
      C=C[:i]+"1"+C[i+1:]
  C=int(C,2)
  tmp=(B-1-A)/2%2
  if tmp%2==1:
    print(C-1)
  else:
    print(C)
elif A%2==0 and B%2==1:
  tmp=(B+1-A)/2%2
  if tmp%2==1:
    print("1")
  else:
    print("0")
elif A%2==0 and B%2==0:
  tmp=(B-A)/2%2
  if tmp%2==1:
    print(B+1)
  else:
    print(B)

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

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

def calc(a):

    cnt = (a+1) // 2
    ans = cnt % 2

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

    return ans

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

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

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


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

    else:
        kosuu = (n - 1) // 2
        kosuu += 1
        if kosuu % 2 == 0:
            res = 0
        else:
            res = 1
    return res


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

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

if __name__ == '__main__':
    main()

Solution (Python):
a,b = map(int,input().split())
def F(x):
  return ((x+1)//2)%2 ^ x*(x%2==0)
print(F(b)^F(a-1))

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

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


def calc(a):
    
    cnt1 = (a+1)//2
    ans = cnt1 % 2

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

    return ans    

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

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(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//2)%2==0: return 1
        else: return 0
    

def main():
    A, B = input_nums()
    print(xor(B)^xor(A-1))
    
if __name__ == '__main__':
    main()

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


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

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


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


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

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


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

Solution (Python):
a,b=map(int,input().split())
n=len(bin(b))-2

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

for i in range(1,n):
    now=2**(i+1)
    ra=a%now
    rb=b%now
    c=2**i
    cnt=0
    if rb-c>=0:
        cnt+=rb-c+1
    if ra-c>0:
        cnt+=now-ra
    else:
        cnt+=now-c
    ans+=(cnt%2)*c
print(ans)

Solution (Python):
a, b = map(int, input().split())
x = []
if a % 2 == 0:
    m = a
else:
    m = a + 1
    x.append(a)
if b % 2 == 1:
    l = b
else:
    l = b - 1
    x.append(b)
x.append(((l - m + 1) // 2) % 2)
ans = 0
for i in x:
    ans ^= i
print(ans)

Solution (Python):
a,b=map(int,input().split())
ans=0
for i in range(40):
  p1=2**i
  p2=2**(i+1)
  c=a//p2*p1+max(a%p2-p1,0)
  d=(b+1)//p2*p1+max((b+1)%p2-p1,0)
  ans+=(d-c)%2*p1
print(ans)

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

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


def bit_sum(x):
    bit = [0] * n
    x += 1
    for i in range(n):
        bit[i] = x // 2**(i + 1) * 2**i + max(0, x-1-x // 2**(i+1) * 2**(i+1) + 1 - 2**i)
    return reversed(bit)


a_bit = bit_sum(a-1)
b_bit = bit_sum(b)

ans = ''.join(str((i+j) % 2) for i, j in zip(a_bit, b_bit))
print(int(ans, 2))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

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


if __name__ == '__main__':
    main()

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

Solution (Python):
A, B = map(int, input().split())
def length(a):
    count=0
    while a>0:
        a=a//2
        count+=1
    return count

def make_sum(X):
    X_len=length(X)
    each = [0] * X_len
    for i in range(X_len):
        temp = (X+1) //2**(i + 1)*2**i + max((X+1) % 2 ** (i + 1) - 2 ** i, 0)
        each[i] = temp
    return each



A_lst=make_sum(A-1)
B_lst=make_sum(B)
A_lst+=[0]*(length(B)-length(A-1))
maxlen=length(B)

answer=0
for i in range(maxlen):
    answer+= ((B_lst[i]-A_lst[i])%2)*2**i

print(answer)

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

    if a % 2:
        s = a
        a += 1
    else:
        s = 0

    if b % 2 == 0:
        r = b
        b -= 1
    else:
        r = 0
    p = (b - a + 1) // 2
    p %= 2
    print(s ^ r ^ p)


submit()

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

B=[int(c) for c in format(B,'b')]

n=len(B)
dp=[[0,0] for _ in range(n+1)]
dp[0][0]=1

cnt=[0]*(n+1)

s=''

for i in range(1,n+1):
    dp=[[0,0] for _ in range(n+1)]
    dp[0][0]=1
    for j in range(n):
        for k in range(2):
            if i==j+1:
                dp[j+1][k]=0 if B[j]==0 and k==0 else dp[j][k]
            else:
                for l in range(0,2 if k==1 else B[j]+1):
                    dp[j+1][k or l<B[j]]+=dp[j][k]
    
    cnt[i]=dp[n][0]+dp[n][1]

if A>1:
    A-=1
    A=[int(c) for c in format(A,'b')]
    n=len(A)
    
    for i in range(1,n+1):
        dp=[[0,0] for _ in range(n+1)]
        dp[0][0]=1
        for j in range(n):
            for k in range(2):
                if i==j+1:
                    dp[j+1][k]=0 if A[j]==0 and k==0 else dp[j][k]
                else:
                    for l in range(0,2 if k==1 else A[j]+1):
                        dp[j+1][k or l<A[j]]+=dp[j][k]
        
        cnt[i+len(B)-n]-=dp[n][0]+dp[n][1]

for i in range(1,len(B)+1):
    if cnt[i]%2==0:
        s+='0'
    else:
        s+='1'

print(int(s,2))

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

a,b = inm()
s = [1 if (a%4,b%4) in \
   [(0,1),(0,2),(1,1),(1,2),(2,3),(2,0),(3,3),(3,0)] else 0]
for i in range(1,44):
    bit = 1<<i
    aa = 0 if a&bit==0 else a%2
    bb = 0 if b&bit==0 else (b+1)%2
    s.append((aa+bb)%2)
    
    
print(sum([s[i]*2**i for i in range(len(s))]))

Solution (Python):
A, B = map(int, input().split())
N = B - A + 1
pn, ans = 0, 0

def p(pn):
  if pn % 2 == 0: return 0
  else: return 1

if A % 2 == 0:
  pn = N // 2
  if B % 2 == 0:
    ans = p(pn) ^ B
  else:
    ans = p(pn)
else:
  pn = (N - 1) // 2
  if B % 2 == 0:
    ans = A ^ p(pn) ^ B
  else:
    ans = A ^ p(pn)

print(ans)

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

A, B = map(int, input().split())
if B - A <= 10:
    print(reduce(lambda x, i: x ^ i, range(A, B + 1)))
    exit()
ans = 0
while A % 4 != 0:
    ans ^= A
    A += 1
while B % 4 != 3:
    ans ^= B
    B -= 1
print(ans)

Solution (Python):
def calc_odd(n):
    return (n + 1) // 2 % 2


def calc(n):
    if n % 2 == 1:
        return calc_odd(n)
    else:
        return calc_odd(n + 1) ^ (n + 1)


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

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

Solution (Python):
def F(N):
    if ((N+1) // 2) % 2 == 0:
        bit = 0
    else:
        bit = 1
    if N % 2 == 0:
        return bit ^ N
    else:
        return bit

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a, b = MAP()
bit = [[0, 0] for _ in range(40)]
for i in range(40):
    p1 =  pow(2, i)
    p2 = pow(2, i + 1)
    bit[i][0] = a // p2 * p1 + max(a % p2 - p1, 0)
    bit[i][1] = (b + 1) // p2 * p1 + max((b + 1) % p2 - p1, 0)
ansbit = [(bit[i][1] - bit[i][0]) % 2 for i in range(40)]
ans = 0
for i in range(40):
    ans += ansbit[i] * pow(2, i)
print(ans)

Solution (Python):
from sys import stdin
def f(n):
    if n%4==0:
        return n
    elif n%4==2:
        return 1^n
    elif n%4==1:
        return 1
    else:
        return 0

def main():
    
    readline=stdin.readline
    A,B=map(int,readline().split())
    if A==0 and B==0:
        print(0)
    elif A==0:
        print(f(B))
    else:
        print(f(B)^f(A-1))

if __name__=="__main__":
    main()

Solution (Python):

import os
from sys import stdin, stdout

__LOCAL__ = False
if(__LOCAL__):
    __dirname = os.path.dirname(__file__)
    __basename = os.path.splitext(os.path.basename(__file__))[0]
    __inputname = './input/' + __basename + '.txt'
    __outputname = './output/' + __basename + '.txt'
    input_path = os.path.join(__dirname, __inputname)
    output_path = os.path.join(__dirname, __outputname)
    stdin = open(input_path)
    stdout = open(output_path, "w")

def TLEmain():
    A, B = map(int,stdin.readline().rstrip().split(' '))
    ans = 0
    for x in range(A,B+1):
        ans ^= x
    print(ans)

def xorsum(A):
    if(A&1):
        return (A+1)//2 & 1
    else:
        return ((A+1)//2 & 1) ^ A

def main():
    A, B = map(int,stdin.readline().rstrip().split(' '))
    if(A==B):
        ans = A
        stdout.write("{}\n".format(ans))
    else:
        ans = xorsum(A-1)^xorsum(B)
        stdout.write("{}\n".format(ans))     

if __name__ == "__main__":
    main()

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

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

if b%2==0:
    fb=((b//2)%2)^b
else:
    fb=((b+1)//2)%2
    
print(fb^fa)

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

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

def xor_zero2n(n):
    remainder4 = n%4
    ret = 0
    for i in range(remainder4+1):
        ret ^= n-i
    return ret

def xor_a2b(a,b):
    return xor_zero2n(a-1)^xor_zero2n(b)

print(xor_a2b(a,b))

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

def f(x):
    ret = []
    i = 1
    x += 1
    while 1:
        r,q = divmod(x, 2**i)
        z = (2**(i-1)) * r + min(q, 2**(i-1))
        o = x - z
        if o == 0:
            break
        ret.append([z,o])
        i += 1
    return ret

a -= 1

a_bin = f(a)
b_bin = f(b)

la = len(a_bin)
lb = len(b_bin)

a_bin = a_bin + [[a+1, 0] for i in range(lb-la)]




ans = 0

for i in range(lb):
    one = b_bin[i][1] - a_bin[i][1]
    one = one%2
    ans += (2**i) * one

print(ans)

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

def xor(A):
  ans = ((A+1)//2)%2
  if A%2==0:
    ans ^= A
  return ans

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

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

Solution (Python):
def f(a):
    i = 1
    r = 1 if a % 4 in (1, 2) else 0
    t = a & 1
    a >>= 1
    while a:
        t |= (a & 1) << i
        if a & 1:
            r |= ((t % (1 << i) + 1) & 1) << i
        a >>= 1
        i += 1
    return r

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

main()

Solution (Python):

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

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

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

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

if A % 2 == 1:
    ans = A
    A += 1
else:
    ans = 0

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

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

print(ans)

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

if a % 2 == 0:
  mod = (b-a) % 4
  
  xor = b - mod
  for i in range(b-mod+1, b+1):
    xor ^= i
    
else:
  tmp = a+1
  mod = (b-tmp) % 4
  
  xor = a
  for i in range(b-mod, b+1):
    xor ^= i
    
print(xor)

Solution (Python):









import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

def main():
    a, b = list(map(int,ipti().split()))
    am1 = max(a-1,0)

    am1_xor = xor0(am1)
    b_xor = xor0(b)

    print(am1_xor^b_xor)

if __name__ == '__main__':
    main()

Solution (Python):

a,b = map(int,input().split())
for aa in range(a,a+4):
    if aa%4==0:
        break
for bb in range(b,b-4,-1):
    if bb%4==0:
        break

bins=[]
for ia in range(a,aa):
    bins.append(bin(ia)[2:])
for ib in range(bb,b+1):
    bins.append(bin(ib)[2:])
    
l = max(len(bi) for bi in bins)
bins_fill = [bi.zfill(l) for bi in bins]
ans=[]
for i in range(l):
    bit =sum( int(bi[i]) for bi in bins_fill )%2
    ans.append( str( bit ) )
ans = "".join(ans)

print( int( ans,2) )

Solution (Python):



import numpy
from math import floor

def main():
  A, B = map(int, input().split())
  A -= 1
  ans = 0
  for i in range(64):
    ca, cb = 0, 0
    if A >= 2**i:
      x = A - 2**i
      ca = (2**i) * (floor(x/(2**(i+1)))) + min(x % (2**(i+1)) + 1, 2**i)
    if B >= 2**i:
      x = B - 2**i
      cb =  (2**i) * (floor(x/(2**(i+1)))) + min(x % (2**(i+1)) + 1, 2**i)
    ans += (2**i) * ((cb - ca) % 2)
  print(ans)
  
if __name__=='__main__':
  main()

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

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

ans = xor_sum(b)^xor_sum(max(0, a-1))
print(ans)

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

def fx(num):
    if num%2==1:
        return ((num-1)//2)%2
    else:
        one = ((num-1)//2)%2
        return num^one

print(fx(max(a-1, 0))^fx(b))

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions

from functools import reduce

import heapq
sys.setrecursionlimit(100001)






def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList




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




def countNum(num):
    cnt = 0
    ans_cnt = []

    while(True):
        tmp_n = pow(2, cnt)
        tmp_n1 = pow(2, cnt+1)

        if tmp_n > num:
            return ans_cnt

        tmp_ans = (num // tmp_n1) * tmp_n + max(0, (num % tmp_n1) - (tmp_n - 1))
        ans_cnt.append(tmp_ans)
        cnt += 1


a_num = countNum(a-1)
b_num = countNum(b)

for i in range(len(a_num)):
    b_num[i] -= a_num[i]

cnt = 0
ans = 0
for b in b_num:
    if b % 2 == 1:
        ans += pow(2, cnt)
    cnt += 1

print(ans)

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()

def f(x):
    if x % 2 == 1:
        
        tmp = (x + 1) / 2
        if tmp % 2 == 0:
            return 0
        else:
            return 1
    else:
        return f(x-1) ^ x
print(f(A-1) ^ f(B))

exit()
if A % 2 == 0 and B % 2 != 0:
    dist = B - A
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
if A % 2 == 0 and B % 2 == 0:
    dist = B - 1 - A
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ B
if A % 2 != 0 and B % 2 != 0:
    dist = B - (A + 1)
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ A
if A % 2 != 0 and B % 2 == 0:
    dist = B - 1 - (A + 1)
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ A ^ B


print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()



if A % 2 == 0 and B % 2 != 0:
    dist = B - A
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
if A % 2 == 0 and B % 2 == 0:
    dist = B - 1 - A
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ B
if A % 2 != 0 and B % 2 != 0:
    dist = B - (A + 1)
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ A
if A % 2 != 0 and B % 2 == 0:
    dist = B - 1 - (A + 1)
    one_num = dist // 2 + 1
    if one_num % 2 == 0:
        ans = 0
    else:
        ans = 1
    ans = ans ^ A ^ B


print(ans)

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

def oddsolve(a):
    return ((a+1)/2)%2
def solve(a):
    if (a%2==1):
        return oddsolve(a)
    else:
        return int(oddsolve(a+1)) ^ (a+1)


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

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


def xor_upto(x):
    b = int(x % 4 == 1 or x % 4 == 2)
    div = 2
    r = x % div
    q = x // div
    while q > 0:
        xor = int(q % 2 == 1 and r % 2 == 0)  
        b += xor * div
        div *= 2
        r = x % div
        q = x // div

    return b

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

print(ans)