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().split())



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

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

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

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

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

Solution (Python):
A, B = map(int,input().split())
F1 = A
F2 = B + 1
if (F1 // 2) % 2 == 0:
  tmp1 = 0
else:
  tmp1 = 1
if F1 % 2 != 0:
  tmp1 ^= A - 1

if (F2 // 2) % 2 == 0:
  tmp2 = 0
else:
  tmp2 = 1
if F2 % 2 != 0:
  tmp2 ^= B
print(tmp1 ^ tmp2)

Solution (Python):
from operator import xor

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


def f(n):
    if n % 2 == 0:
        if n % 4 == 0:
            return n
        else:
            return xor(n, 1)
    else:
        return xor(n, f(n - 1))


print(xor(f(A - 1), f(B)))

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

Solution (Python):
a, b = map(int, input().split())
if a == b:
    print(a)
elif b - a <= 3:
    result = a
    for i in range(a + 1, b + 1):
        result = result ^ i
    print(result)
else:
    period = [0] * 4
    x = a
    period[x % 4] = x
    for i in range(a + 1, a + 4):
        x = x ^ i
        period[i % 4] = x
    if b % 4 == 0:
        result = period[3]
        result = result ^ b
        print(result)
    elif b % 4 == 1:
        print(period[1])
    elif  b % 4 == 2:
        result = period[1]
        result = result ^ b
        print(result)
    else:
        print(period[3])

Solution (Python):


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

def from_zero_ones_in_digit(X, n):
    if n > len(str(bin(X))):
        return 0
    else:
        return (X//(2**n))*2**(n-1) + max(0, X % (2**n) - (2**(n-1) - 1))

ans = 0
for n in range(1, len(str(bin(B)))):
    if (from_zero_ones_in_digit(B, n) - from_zero_ones_in_digit(A-1, n)) % 2 == 1:
        ans += 2**(n-1)

print(ans)

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

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

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==3:
        return 0
    else:
        return (n // 4) * 4 + 3

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

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


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


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


if __name__ == '__main__':
    main()

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

def F(v):
    tmp = v // 2
    amari = v % 2
    ans = 0
    if tmp % 2 == 0:
        if amari != 0:
            ans = v - 1
    else:
        if amari != 0:
            ans = 1 ^ (v - 1)
        else:
            ans = 1
    return ans

ansA = F(A)
ansB = F(B + 1)
print(ansA ^ ansB)

Solution (Python):


a,b=map(int,input().split())
n_even=(b//2)-(a-1)//2

if (b-a+1)%2:
    if a%2:
        print(a^(n_even%2))
    else:
        print(b^((n_even-1)%2))
else:
    if a%2:
        print(a^b^((n_even-1)%2))
    else:
        print(n_even%2)

Solution (Python):
n,m=map(int,input().split())

def ans(n):
    if n%4==0:
        return n
    elif n%4==1:
        return (n-1)^n
    elif n%4==2:
        return (n-2)^(n-1)^n
    else:
        return (n-3)^(n-2)^(n-1)^n
print(ans(m)^ans(n-1))

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

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

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

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

Solution (Python):
def calc(n):
    if (n <= 0): return 0
    ret = 0
    n += 1
    for i in range(1, 50):
        l = 1 << i
        
        cnt = (n // l) * (l // 2)
        cnt += max(0, (n % l) - (l // 2) )            
        if (cnt % 2 == 1):
            
            ret += (1 << (i-1))
    return ret

A, B = [int(x) for x in input().split()]
ans = calc(A-1) ^ calc(B)
print(ans)

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

def g(n):
    if n%4 == 1:
        return 1
    elif n%4 == 2:
        return 1^n
    elif n%4 == 3:
        return 0
    else:
        return n
    
print(g(A-1)^g(B))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


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


a, b = LI()
print(sequence_xor(a - 1) ^ sequence_xor(b))

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

A, B = LI()

da = int(0)
db = int(0)

a = A-1
b = B

if a%2==0:
    da = a
if ((a+1)//2)%2==1:
    da +=1

if b%2==0:
    db = b
if ((b+1)//2)%2==1:
    db +=1

ans = da^db
print(ans)

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

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

Solution (Python):
a,b = map(int,input().split())
ans = 0
if a%2 == 0:
    for i in range(a,a+4):
        ans ^= i
        if i == 0:
            continue
        if ans == 0:
            break
    m = (b-i)%4
    for r in range(m):
        ans ^= b
        b -= 1
else:
    ans = a
    m = (b-a)%4
    for r in range(m):
        ans ^= b
        b -= 1
print(ans)

Solution (Python):
def sumxor(x):
    if x % 4 == 3:
        return 0
    else:
        return x ^ sumxor(x-1)

a, b = [ int(v) for v in input().split() ]
print(sumxor(b) ^ sumxor(a-1))

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

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

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

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

if ((B - A + 1) // 2) % 2 == 1 and A <= B:
    ans ^= 1

print(ans)

Solution (Python):

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

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

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

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

for i in range(1,42):
    count=0
    v,mod1=divmod(a,2**i)
    w,mod2=divmod(b,2**i)
    if v==w:
        
        if mod2<2*(i-1):
            pass
        if mod2>=2**(i-1) and mod1<2**(i-1):
            count+=mod2+1-2**(i-1)
        if mod2>=2**(i-1) and mod1>=2**(i-1):
            count+=mod2-mod1+1
    if v<w:
        
        count+=2**(i-1)*(w-v-1)
        if mod1<2**(i-1):
            count+=2**(i-1)
        if mod1>=2**(i-1):
            count+=(2**i-mod1)
        if mod2<2**(i-1):
            pass
        if mod2>=2**(i-1):
            count+=mod2+1-2**(i-1)


    if count%2!=0:
        ans+=2**(i-1) 

print(ans)

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


if __name__ == "__main__":
    main()

Solution (Python):
def F(x):
    
    
    if not x&1:
        y = x >> 1
        return y&1
    else:
        return (x-1)^F(x-1)

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

Solution (Python):



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

def g(x):
    x1 = (x&1) ^ (x>>1&1)
    x2 = 0
    if not x%2:
        x2 = (x>>1)<<1
    return x1^x2

ans = g(b)^g(a-1)

print(ans)

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


def func(i: int) -> int:
    if i % 2 == 0:
        j = i // 2
        if j % 2 == 0:
            return 0 ^ i
        else:
            return 1 ^ i
    else:
        j = i // 2
        if j % 2 == 0:
            return 0 ^ (i-1) ^ i
        else:
            return 1 ^ (i-1) ^ i


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


if __name__ == '__main__': main()

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

a = A % 2
b = B % 2
c = B - A + 1

if A == B:
    print(A)
elif c == 3:
    print(A ^ (A + 1) ^ B)
elif a == 0:
    x = c % 4
    ans = 0
    for i in range(x):
        ans ^= B - i
    print(ans)
else:
    x = (c - 1) % 4
    ans = A
    for i in range(x):
        ans ^= B - i
    print(ans)

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

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

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

def f(x) :
    ret = 0
    b = 1
    for i in range(44) :
        c = (x // (b * 2)) * b
        rest = x % (b * 2)
        if rest - b > 0 :
            c += rest - b
        if c & 1 :
            ret += 1 << i
        b <<= 1
    return ret
    
print(f(A)^f(B+1))

Solution (Python):
a,b = map(int,input().split())
def XOR(start,end):
  xor =  start
  if end-start < 10:
      for i in range(a+1,b+1):
        xor = xor^i
        
      print(xor)
  else:
    if start%2==0:
      new_start = start-1
    else:
      new_start = start
    
    if (end - new_start)%4==0:
      if start%2==0:
        print(0)
      else:
        print(start)
    elif (end - new_start)%4==1:
      if start%2==0:
        print(end)
      else:
        print(start^end)
    elif (end - new_start)%4==2:
      if start%2==0:
        print((end-1)^end)
      else:
        print(start^(end-1)^end)
    else:
      if start%2==0:
        print((end-2)^(end-1)^end)
      else:
        print(start^(end-2)^(end-1)^end)

if __name__ ==  '__main__':
  XOR(a,b)

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

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

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

"""
A~Bを～～したのを求めよ
→0~Bまで～～したものから、0~A-1まで～～したものを引くのが定石
また、 (2*n) ^ (2n+1) = 1　奇数では成り立たない
"""
def xors(n):
    ret = 0
    d = (n+1) % 4
    
    if d == 0:
        ret = 0
    
    elif d == 1:
        ret = n
    elif d == 2:
        ret = 1
    else:
        ret = 1 ^ n

    if n == 0: ret = 0

    return ret

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

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

sum = B-A+1

if sum % 2 == 0:
  if A % 2 == 0:
    if sum/2%2 == 0:
      print "0"
    else:
      print "1"
  else:
    if sum/2%2 == 1:
      print A^B^0
    else:
      print A^B^1
else:
  if A % 2 == 0:
    if sum/2%2 == 0:
      print 0^B
    else:
      print 1^B
  else:
    if sum/2%2 == 1:
      print 1^A
    else:
      print 0^A

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

b1=[0,0,1,1]
a1=[0,1,1,0]

def bb(n,a):
  n = 1 << n
  if a%n < n//2:
    return 0
  else:
    return 1 if a%2 else 0

def ba(n,a):
  n = 1 << n
  if a%n < n//2:
    return 0
  else:
    return 0 if a%2 else 1

c=0
n=b
while n>0:
  n = n >> 1
  c += 1

n=b1[a%4]^a1[b%4]
for i in range(2,c+1):
  n |= (ba(i,b)^bb(i,a)) << (i-1)

print(n)

Solution (Python):
a,b=map(int,input().split())
ans=0
if a%2==0:
    ans^=a
    a+=1
if b%2==1:
    ans^=b
    b-=1
if a>b:
    print(ans)
else:
    lst=[0]
    i=1
    while b//(2**i)>0:
        lst.append(b//(2**i)-(a-1)//(2**i))
        i+=1
    h=len(lst)
    for i in range(1,h-1):
        if (lst[i]-lst[i+1])%2==1:
            ans^=2**(i+1)-1
    if lst[h-1]%2==1:
        ans^=2**h-1
    print(ans)

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






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


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

if __name__ == '__main__':
    main()

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

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

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

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

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

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

Solution (Python):
a,b=map(int,input().split())
a_odd = (a%2==1)
b_odd = (b%2==1)

if a_odd and b_odd:
    ans = ((b-a)//2%2)^a
elif a_odd and not b_odd:
    ans = ((b-a-1)//2%2)^a^b
elif not a_odd and b_odd:
    ans = (b-a+1)//2%2
else:
    ans = ((b-a)//2%2)^b
print(ans)

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

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

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

At = A%4
Bt = B%4

ans = 0
if At>0:
    for i in range(4-At):
        ans ^= A+i
if Bt<4:
    for i in range(Bt+1):
        ans ^= B-i
print(ans)

Solution (Python):
def f(n):
    if n%2==0:
        if (n//2)%2==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(f(A-1)^f(B))

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
a,b=map(int,input().split())
if a%2==0:
    if b%2!=0:
        if (b+1-a)//2%2==0:
            print(0)
        else:
            print(1)
    else:
        if (b-a)//2%2==0:
            print(b)
        else:
            print(b^1)
else:
    if b%2!=0:
        if (b-a)//2%2==0:
            print(a)
        else:
            print(a^1)
    else:
        if (b+1-a)//2%2==0:
            print(1^a^b)
        else:
            print(a^b)

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

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

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

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

print(L)

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

def calc(n,k):
  n += 1
  return (n//(2**k))*(2**(k-1))+max(n-(n//(2**k))*(2**k)-(2**(k-1)),0)

ans = ['' for _ in range(40)]
for i in range(40):
  ans[39-i] = str((calc(B,i+1)-calc(A-1,i+1))%2)
print(int(''.join(ans),2))

Solution (Python):
a,b=[int(s) for s in input().split()]
def x(num):
  if num%4==3:
    return 0
  elif num%4==0:
    return num
  elif num%4==1:
    return 1
  else:
    return num^1
print(x(a-1)^x(b))

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

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

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

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

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

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

K = (B - A + 1) // 2
res ^= K % 2
print(res)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Solution (Python):
def calc(A):
    
    A += 1
    cnt = 0
    ans = 0
    
    for i in range(50):
        
        
        
        loop = pow(2,i+1)

        
        cnt = (A // loop) * (loop // 2)

        
        if (A % loop) - (loop // 2) > 0:
            cnt += (A % loop) - (loop // 2)
        
        
        if cnt % 2 == 1:
            ans += 1 << i
    return ans


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

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


main()

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 1 ^ n
    else:
        return 0
    
print(f(A-1) ^ f(B))

Solution (Python):
a,b=map(int,input().split())
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
print(xor(a-1)^xor(b))

Solution (Python):

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


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

Solution (Python):

import sys
from io import StringIO
import unittest
def getxor(i):
    if i%4==0:
        t=i
    elif i%4==1:
        t=1
    elif i%4==2:
        t=i+1
    else:
        t=0
    return t
class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 4"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """123 456"""
        output = """435"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """123456789012 123456789012"""
        output = """123456789012"""
        self.assertIO(input, output)

def resolve():
    (A,B)=(int(i) for i in input().split())
    xx=getxor(A-1)
    yy=getxor(B)
    print(xx^yy)
if __name__ == "__main__":
    resolve()

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    if a % 2 == 0 and b % 2 == 0:
        print(b ^ ((b - a) // 2 % 2))
    elif a % 2 == 1 and b % 2 == 1:
        print(a ^ ((b - a) // 2 % 2))
    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 ^ (b - a - 1) // 2 % 2)


if __name__ == '__main__':
    slove()

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

def f(x):
    if x&1:
        if ((x+1)//2)&1:
            tmp = 1
        else:
            tmp = 0
    else:
        tmp = x
        if (x//2)&1:
            tmp = tmp ^ 1
    return tmp

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

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

if __name__ == "__main__":
    main()

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

def nXor(n):
  if n % 2 == 0:
    if (n//2) % 2 == 0:
      return 0 ^ n
    else:
      return 1 ^ n
  else:
    if ((n+1)//2) % 2 == 0:
      return 0
    else:
      return 1
n = 0
for i in range(9):
  n = n^i
print (nXor(A-1) ^ nXor(B))

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

Solution (Python):

"""
H, W = map(int, input().split())
h, w = map(int, input().split())
print(H*W-h*W-w*H+h*w)
"""

"""
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
ansb = 0
for i in range(n):
    ans = 0
    a = list(map(int, input().split()))
    for k in range(m):
        ans += a[k]*b[k]
    ans += c
    if ans > 0:
        ansb += 1
print(ansb)
"""

"""
n, m = map(int, input().split())
ans = []
ansnum = 0
honsuu = 0
for i in range(n):
    a = list(map(int, input().split()))
    ans.append(a)
ans.sort()
for i in ans:
    if honsuu + i[1] <= m:
        ansnum += i[0] * i[1]
        honsuu += i[1]
    else:
        ansnum += (m - honsuu) * i[0]
        break

print(ansnum)
"""




a, b = map(int, input().split())
def F(x):
    tmp1, tmp2 = (x+1) >> 1, x & 1
    rast = 0 if tmp2 else x
    fast = tmp1 & 1
    return rast ^ fast
print(F(a - 1) ^ F(b))

Solution (Python):
a,b=map(int,input().split())
i=1
ans=0
while 2**(i-1)<=b:
  if i==1:
    d=(b-a+1)//2
    if a%2==b%2==1:
      d+=1
    ans+=d%2    
  else:
    x=a%(2**i)
    y=b%(2**i)
    d1=min(2**(i-1),2**i-x)
    d2=max(y-2**(i-1)+1,0)
    if (d1+d2)%2==1:
      ans+=2**(i-1)
  i+=1
print(ans)

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

def int_to_bit(N):
  lst=[]
  ans=''
  if N==0:
    return 0
  while N!=1 and N!=0:
    lst.append(str(N%2))
    N//=2
  for i in range(1,len(lst)+1):
    ans+=lst[-i]
  if N==0:
    pass
  else:
    ans='1'+ans
  return int(ans)

def bit_to_int(N):
  N=str(N)
  ans=0
  for i in range(len(N)):
    ans+=int(N[i])*2**(len(N)-1-i)
  return ans

def XOR(a,b):
  a,b=min(a,b),max(a,b)
  a,b=str(a),str(b)
  length=len(a)
  lst=[]
  ans=''
  for i in range(1,length+1):
    if a[-i]==b[-i]=='1' or a[-i]==b[-i]=='0':
      lst.append('0')
    else:
      lst.append('1')
  for i in range(1,length+1):        
    ans+=lst[-i]
  if length==len(b):
    pass
  else:
    add=b[0:len(b)-length]
    ans=add+ans
  return bit_to_int(ans)

if A%2==0 and B%2==0:
  v=(B-A)//2
  if v%2==0:
    print(B)
  else:
    print(XOR(1,int_to_bit(B)))
elif A%2==0 and B%2==1:
  v=(B-A+1)//2
  if v%2==0:
    print(0)
  else:
    print(1)
elif A%2==1 and B%2==0:
  v=(B-1-A)//2
  if v%2==0:
    print(XOR(int_to_bit(A),int_to_bit(B)))
  else:
    print(XOR(1,int_to_bit(XOR(int_to_bit(A),int_to_bit(B)))))
else:
  v=(B-A)//2
  if v%2==0:
    print(A)
  else:
    print(XOR(int_to_bit(A),1))

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

Solution (Python):
X,Y=map(int,input().split())
if X % 2 ==0:
    if (Y-X) % 4 == 0:
        print(0^Y)
    elif (Y-X) % 4 == 1:
        print(1)
    elif (Y-X) % 4 == 2:
        print(1^Y)
    elif (Y-X) % 4 == 3:
        print(0)
elif X % 2 ==1:
    if (Y-X) % 4 == 0:
        print(X^0)
    elif (Y-X) % 4 == 1:
        print(X^Y)
    elif (Y-X) % 4 == 2:
        print(X^1)
    elif (Y-X) % 4 == 3:
        print(X^1^Y)

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


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


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

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


def f(x):
    xx = bin(x)[2:]
    res = ''
    for c in xx[:-1]:
        if c == '1':
            if xx[-1] == '1':
                res += '0'
            else:
                res += '1'
        else:
            res += '0'
    if (x - 1) % 4 < 2:
        res += '1'
    else:
        res += '0'
    return res


a = f(a - 1)
b = f(b)
n = max(len(a), len(b))
a = a.rjust(n, '0')
b = b.rjust(n, '0')
c = ''
for x, y in zip(a, b):
    if x == y:
        c += '0'
    else:
        c += '1'
print(int(c, 2))

Solution (Python):

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

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

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

print(ans)

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











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




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

"""

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

print(ans)
"""

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







def f(n):
    ans = 0
    n += 1
    for i in range(40): 
        loop = 2**(i+1)
        cnt = (n // loop) * (loop // 2) 
        cnt += max(0, (n % loop) - (loop // 2)) 
        if cnt % 2 == 1:
            ans += 2**i 
    return(ans)

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

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

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

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

"""
ans = A
for i in range(A+1, B+1):
    ans ^= i

print(ans)
"""

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

Solution (Python):
import sys
MAX_INT = int(10e9)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b = IL()

num = (b-a+1)//2
if a%2 != 0 and b%2 ==0:
  num -= 1
if num%2 == 0:
  c = 0
else:
  c = 1

if a%2 == 0:
  if b%2 == 0:
    print(b^c)
  else:
    print(c)
else:
  if b%2 == 0:
    print(a^b^c)
  else:
    print(a^c)

"""
10 14
10 13
9 14
9 13
"""

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

if __name__ == '__main__':
    A, B = map(int, input().split())
    
    A_bi = bin(F_0(A-1))[2:]
    B_bi = bin(F_0(B))[2:]
    
    answer=[]
    
    if len(A_bi) > len(B_bi):
        A_bi, B_bi = B_bi, A_bi
        
    max_len = len(B_bi)
    pad = max_len - len(A_bi)
    A_bi = '0'*pad + A_bi
    
    for i in range(max_len):
        
        if A_bi[i] == B_bi[i]:
            answer.append('0')
        else:
            answer.append('1')
        
    print(int(''.join(answer), 2))

Solution (Python):
if __name__ == '__main__':
    A, B = map(int, input().split())
    
    digit_max = len(bin(B)[2:])
    answer = []
    for digit in range(1, digit_max+1):
        mod = (2**digit)
        A_mod = A%mod
        B_mod = B%mod
        
        if digit == 1:
            length = B-A + 1
            if length%2 == 0:
                if (length//2)%2 == 1:
                    ret = 1
                else:
                    ret = 0
                
            else:
                if A%2 == 0:
                    if ((length - 1)//2)%2 == 1:
                        ret = 1
                    else:
                        ret = 0      
                else: 
                    if ((length - 1)//2)%2 == 0:
                        ret = 1
                    else:
                        ret = 0
            
        else:
            if A_mod >= mod//2:
                if A%2 == 1:
                    start = 1
                else:
                    start = 0
            else:
                start = 0

            if B_mod >= mod//2:
                if B%2 == 0:
                    end = 1
                else:
                    end = 0
            else:
                end = 0
            
            if start == end:
                ret = 0
            else:
                ret = 1
        
        answer.append(str(ret))
    
    
    print(int(''.join(answer[::-1]), 2))