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())
if A == B:
    print(A)
    exit()

ans = 0
max_digit = math.floor(math.log2(B)) + 1
plus_count = B - A + 1


for digit in range(max_digit):
    start_pos = A % (2**(digit + 1))
    pos_len = 2**(digit + 1)
    digit_sum = 0
    if start_pos + plus_count > pos_len:
        end_pos = (plus_count - (pos_len - start_pos)) % pos_len
        if end_pos == 0:
            digit_sum = pos_len - max(2**digit, start_pos) + (
                plus_count - (pos_len - start_pos)) // pos_len * (2**digit)
        else:
            digit_sum = pos_len - max(2**digit, start_pos) + (
                plus_count -
                (pos_len - start_pos)) // pos_len * (2**digit) + max(
                    end_pos - 2**digit, 0)
    else:
        end_pos = start_pos + plus_count - 1
        digit_sum = 2**digit - max(start_pos - 2**digit,
                                   0) - (pos_len - max(2**digit, end_pos + 1))
    if digit_sum % 2 == 1:
        ans += 2 ** digit
print(ans)

Solution (Python):

















import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")





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

A, B = l_inpl()
print(calc(A-1)^calc(B))

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

ans = 0

a, b = li()

ap4 = a//4
bp4 = b//4

if ap4 == bp4:
    for x in range(a, b+1):
        ans ^= x

else:
    while a%4:
        ans ^= a
        a += 1

    while b%4 != 3:
        ans ^= b
        b -= 1

print(ans)

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

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

    print(ans)

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

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

Solution (Python):
a,b = map(int,input().split())
B = format(b,"b")
digit = len(B)
A = format(a,"0"+str(digit)+"b")
def xor(a,b):
    if a and not(b):
        return True
    elif not(a) and b:
        return True
    else:
        return False
ans = 0
for i in range(digit):
    div = 2**(digit-1-i)
    tempa = a%div if A[i] == "1" else 0
    tempb = 1+b%div if B[i] == "1" else 0
    
    if div == 1:
        if b-a == 0:
            ans += int(A[i])
        elif A[i] == "1" and ((b-a+1)%4 == 1 or (b-a+1)%4== 2):
            ans += 1
        elif A[i] == "0" and ((b-a+1)%4 == 2 or (b-a+1)%4== 3):
            ans += 1
    elif b-a > div:
        if (tempa+tempb)%2 == 1:
            ans += div
    else:
        if xor(tempa%2 == 1,tempb%2 == 1):
            ans += div
print(ans)

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

def acc_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(acc_xor(a-1)^acc_xor(b))

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

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

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

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

def f_ab(A, B):
    return(f_n(A-1) ^ f_n(B))
    
    
A, B = map(int, input().split())

print(f_ab(A, B))

Solution (Python):
import math
A, B = map(int,input().split())
if A == 0:
    if B % 4 ==0:
        print(B)
    elif B % 4 == 1:
        print(1)
    elif B % 4 == 2:
        print(B+1)
    else:
        print(0)
elif A == B:
    print(A)
else:
    LA = []
    LB = []
    for i in range(int(math.log2(A))+1):
        P = A % (2**(i+1))
        Q = P % (2**i)
        R = (P-Q)//(2**i)
        LA.append(R)
    for i in range(int(math.log2(B))+1):
        P = B % (2**(i+1))
        Q = P % (2**i)
        R = (P-Q)//(2**i)
        LB.append(R)
    LS = []
    def Q(a,b):
        return (a%2,b%2)
    if A == B-1:
        if Q(A,B) == (0,1):
            print(1)
        else:
            LS.append(1)
            if len(LA) == len(LB):
                for i in range(1,len(LA)):
                    LS.append((LA[i]+LB[i])%2)
            else:
                for i in range(len(LA)):
                    LS.append(1)
            ANS = 0
            for i in range(len(LS)):
                ANS += (2**i)*LS[i]
            print(ANS)
    else:
        if Q(A,B) == (0,0):
            if (B-A+1)%4 ==1:
                print(B)
            else:
                print(B+1)
        elif Q(A,B) == (0,1):
            if (B-A+1)%4 == 0:
                print(0)
            else:
                print(1)
        elif Q(A,B) == (1,0):
            if (B-A+1)%4 == 0:
                LS.append(0)
            else:
                LS.append(1)
            if len(LA) > 1:
                for i in range(1,len(LA)):
                    LS.append((LA[i]+LB[i])%2)
            if len(LB) > len(LA):
                for i in range(len(LA),len(LB)):
                    LS.append(LB[i])
            ANS = 0
            for i in range(len(LS)):
                ANS += (2**i)*LS[i]
            print(ANS)
        else:
            if (B-A+1)%4 == 1:
                print(A)
            else:
                print(A-1)

Solution (Python):


import sys


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main_lte():
    A, B = i2nn()
    n = A
    for i in range(A+1, B+1):
        n ^= i
    print(n)


def calc_t(n, t):
    d = n % (2**t)
    h = 2**(t-1)
    if d >= h and d % 2 == 0:
        return h
    else:
        return 0


def calc_old(n):
    ans = 0
    
    
    
    d = n % 4
    if d == 1 or d == 2:
        ans += 1
    
    d = n % 4
    if d == 2:
        ans += 2
    
    d = n % 8
    if d == 4 or d == 6:
        ans += 4
    
    d = n % 16
    if d == 8 or d == 10 or d == 12 or d == 14:
        ans += 8
    return ans

def calc(n):
    ans = 0
    
    d = n % 4
    if d == 1 or d == 2:
        ans += 1
    
    for t in range(2, 40+1):
        ans += calc_t(n, t)
    return ans




def main():
    A, B = i2nn()
    n = calc(A-1) ^ calc(B)
    print(n)

main()

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

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

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

Solution (Python):

import sys


def ff(n):
    n2 = (n+1)/2
    if n2 % 2 == 0:
        return 0
    else :
        return 1

def f(n):
    if n % 2 == 1:
        return ff(n)
    else:
        return ff(n-1)^n



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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    solve(A, B)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def f(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,input().split())
print(f(B)^f(max(A-1,0)))

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

Aodd = -1
Beven = -1
if A % 2 == 1:
    Aodd = A
    A += 1
if B % 2 == 0:
    Beven = B
    B -= 1

ans = ((B-A) // 2 + 1) % 2
if Aodd != -1:
    ans = ans ^ Aodd
if Beven != -1:
    ans = ans ^ Beven

print(ans)

Solution (Python):

import numpy


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

num = B-A+1

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

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

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

def xor_0a(a):
  if a%4 == 0:
    return a
  elif a%4 == 1:
    return 1
  elif a%4 == 2:
    return 1 ^ a
  elif a%4 == 3:
    return 0
  
xorA1 = xor_0a(A-1)
xorB = xor_0a(B)
print(xorA1 ^ xorB)

Solution (Python):



def count(n, k):
    
    pow2k = 2**k
    q, mod = divmod(n+1, 2**(k+1))
    c1 = max(mod-2**k, 0)
    c2 = q * 2**k
    return c1 + c2

def main():
    A, B = list(map(int, input().split()))
    K = 0
    tmp = 1
    while tmp <= B:
        K += 1
        tmp *= 2

    ret = 0
    for k in range(K):
        ca = count(A-1, k)
        cb = count(B, k)
        ret += ((cb-ca)%2) * (2**k)
    print(ret)


if __name__ == '__main__':
    main()

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


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

Solution (Python):
import math

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

if a % 2 == 0 and b % 2 == 0:
    if (b - a) % 4 == 0:
        ans = b
    else:
        ans = b + 1
elif a % 2 == 0 and b % 2 == 1:
    if (b - a) % 4 == 3:
        ans = 0
    else:
        ans = 1
elif a % 2 == 1 and b % 2 == 1:
    if (b - a) % 4 == 0:
        ans = a
    else:
        ans = a - 1
else:
    r = int(math.log2(b))
    A = []
    B = []
    for i in reversed(range(r + 1)):
        if a >= 2 ** i:
            a -= 2 ** i
            A.append(1)
        else:
            A.append(0)
        if b >= 2 ** i:
            b -= 2 ** i
            B.append(1)
        else:
            B.append(0)
    ans = 0
    for i in range(r + 1):
        if A[i] != B[i]:
            ans += 2 ** (r - i)
    if A[r - 1] == B[r - 1]:
        ans -= 1

print(ans)

Solution (Python):

A, B = [int(n) for n in input().split()]


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


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

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


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

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

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
B=str(bin(f(b)))[2:]
if a==0:
  A="0"
else:
  A=str(bin(f(a-1))[2:])
m=max(len(A),len(B))
A=A.zfill(m)
B=B.zfill(m)
ans=""
for i in range(len(B)):
  if B[i]==A[i]:
    ans+="0"
  else:
    ans+="1"
print(int(ans,2))

Solution (Python):
def p2(AA):
    A = AA&0xFFFFFFFFFFFFC
    
    a = A
    K = 0
    for i in range(1000):
        if (a>0):
            K+=1
        a//=2
    a = A
    D = 0
    for k in range(K-1,0,-1):
        p2k = 1<<(k)
        if (a-p2k>=0):
            D = (D<<1)+(a-p2k-1)%2
            
            a = a-p2k
        else:
            D = (D<<1)
            
    D<<=1
    for i in range(A+1,AA+1):
        D = D^i
    return D

a,b = [int(it) for it in input().split()]
if (a==0):
  print ( p2(b) )
else:
  print ( p2(b)^p2(a-1) )

Solution (Python):
a, b = map(int, input().split())
if a > 0:
    a -= 1

ax = [a, 1, a + 1, 0][a % 4]
bx = [b, 1, b + 1, 0][b % 4]

print(ax ^ bx)

Solution (Python):

A, B = (int(i) for i in input().split())



def num_bin(a, i):
    mod = 2 ** (i+1)
    hlf = 2 ** i
    base = (a-1) // mod * hlf
    resm = max(((a-1) % mod) - hlf + 1, 0)
    return base + resm

xor = ''

max_index = len(bin(B + 1)) - 2

for i in range(max_index):
    xor = str(num_bin(A, i) % 2 ^ num_bin(B + 1, i) % 2) + xor
    
print(int(xor, 2))

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

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

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

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

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

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

Solution (Python):
a = list(map(int,input().split()))
a[0]-=1
c = [a[0]%4,a[1]%4]
d = [0,0]

for i in range(len(c)):
    if c[i]==0:
        d[i]=a[i]
    elif c[i]==1:
        d[i]=1
    elif c[i]==2:
        d[i]=a[i]+1
    else:
        d[i]=0

print(d[0]^d[1])

Solution (Python):
a = list(map(int,input().split()))
a[0]-=1
c = [a[0]%4,a[1]%4]
d = [0,0]

for i in range(len(c)):
    if c[i]==0:
        d[i]=a[i]
    elif c[i]==1:
        d[i]=1
    elif c[i]==2:
        d[i]=a[i]+1
    else:
        d[i]=0

x,y = map(bin,d)
g = max(len(str(x)),len(str(y)))
x = str(x)[2:].zfill(g-2)
y = str(y)[2:].zfill(g-2)

f = []
for i in range(len(x)):
    if x[-i-1]==y[-i-1]:
        f.append(0)
    else:
        f.append(1)
ans = 0
for i in range(len(f)):
    ans += f[i]*2**i

print(ans)

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

def xorEO(e, o):
  return int((o + 1 - e) / 2) % 2

if a == b:
  print(a)
elif a % 2 == 0 and b % 2 != 0: 
   print(xorEO(a, b))
elif a % 2 == 0 and b % 2 == 0: 
  print(xorEO(a, b - 1) ^ b)
elif b % 2 != 0: 
  print(a ^ xorEO(a + 1, b))
else:  
  print(a ^ xorEO(a + 1, b - 1) ^ b)

Solution (Python):
def get_bin_arr(n):
    arr = []
    while n > 0:
        arr.append(n & 1)
        n >>= 1
    return arr


def bin_arr_to_int(arr):
    return sum([2**i * digit for i, digit in enumerate(arr)])


def count_ones(idx, tier):
    half_cycle = 2**tier
    full_cycle = half_cycle * 2
    return (idx // full_cycle) * half_cycle \
        + max(idx % full_cycle - half_cycle, 0)



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

a = get_bin_arr(A)
b = get_bin_arr(B)

my_max = 10**12
bin_digits = len(get_bin_arr(my_max))


a += [0] * (bin_digits - len(a))
b += [0] * (bin_digits - len(b))

ones = [0] * bin_digits

for i in range(bin_digits):
    ones[i] = count_ones(B + 1, i) - count_ones(A, i)

ans = [i % 2 for i in ones]
print(int(bin_arr_to_int(ans)))

Solution (Python):


from math import log2

def func(n):
    
    
    
    

    
    
    

    if n % 2 == 0:
        m = n // 2
        if m % 2 == 0:
            return n
        else:
            return n ^ 1
    else:
        m = (n-1) // 2
        return 0 if m % 2 == 1 else 1

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

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

if __name__ == '__main__':
    main()

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

a = []
b = []
while Ad > 0:
    a.append(Ad%2)
    Ad //= 2

while Bd > 0:
    b.append(Bd%2)
    Bd //= 2

while len(a) < len(b):
    a.append(0)

a = ''.join(map(str,a))
b = ''.join(map(str,b))

r = []

for i in range(len(a)):
    if i == 0:
        r.append(
            ((B-A)//2+(A%2 or B%2))%2
        )
        continue
    if a[i::] == b[i::]:
        r.append(int(a[i]) and (B-A+1)%2)
        continue
    s = 0
    if a[i] == '1':
        s += A % 2
    if b[i] == '1':
        s += B % 2 + 1
    r.append(s%2)

s = 0
for i in range(len(a)):
    s += r[i] * (2**i)

print(s)

Solution (Python):


from bisect import bisect_left as binl
from math import log10, log2

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x





def main():
    a, b = intin()
    bits = {}

    if not b:
        print(0)
        return 0

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        if (b - a + 1) % 2:
            odd_count = (b - a + 1) // 2 + 1
        else:
            odd_count = (b - a + 1) // 2
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


from bisect import bisect_left as binl
from math import log10, log2, ceil

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x





def main():
    a, b = intin()
    bits = {}

    if not b:
        print(0)
        return 0

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        odd_count = ceil((b - a + 1) / 2)
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()

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,input().split())
print(XOR(A-1)^XOR(B))

Solution (Python):
A, B = map(int, input().split())
sum_1 = 0
sum_2 = 0
ct_1 = 0
if (A-1) % 2:
    if A//2 % 2:
        ct_1 += 1
    else:
        pass
else:
    if (A-1)//2 % 2:
        sum_1 += A-1
        ct_1 += 1
    else:
        sum_1 += A-1
if B % 2:
    if (B+1)//2 % 2:
        ct_1 += 1
    else:
        pass
else:
    if B//2 % 2:
        sum_2 += B
        ct_1 += 1
    else:
        sum_2 += B

if ct_1 % 2:
    ct_1 = 1
else:
    ct_1 = 0

print(ct_1 ^ sum_1 ^ sum_2)

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

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

Solution (Python):
A,B=[int(i) for i in input().split()]
def f(x):
	a=x%4
	if a==3:
		return bin(0)
	elif a==0:
		return bin(x)
	elif a==1:
		return bin(1)
	elif a==2:
		return bin(x+1)
res=[]
A=f(A-1)
B=f(B)
for i,j in zip(A[-1:1:-1],B[-1:1:-1]):
	if i==j:
		res.append('0')
	else:
		res.append('1')
if len(A)>len(B):
	p=A[0:2+abs(len(B)-len(A))]+"".join(res[::-1])
else:
	p=B[0:2+abs(len(B)-len(A))]+"".join(res[::-1])
print(int(p,0))

Solution (Python):
A,B=[int(i) for i in input().split()]
def f(x):
	a=x%4
	if a==3:
		return bin(0)
	elif a==0:
		return bin(x)
	elif a==1:
		return bin(1)
	elif a==2:
		return bin(x+1)
res=[]
A=f(A-1)
B=f(B)
for i,j in zip(A[-1:1:-1],B[-1:1:-1]):
	if i==j:
		res.append('0')
	else:
		res.append('1')
if len(A)>len(B):
	p=A[0:2+abs(len(B)-len(A))]+"".join(res[::-1])
else:
	p=B[0:2+abs(len(B)-len(A))]+"".join(res[::-1])
print(int(p,0))

Solution (Python):
a,b=map(int,input().split())
stra = format(a,'b').zfill(50)
strb = format(b,'b').zfill(50)



summ = 0
numa = int(stra[-1])
numb = int(strb[-1])
if numa == numb:
    if numa==1:
        if (b-a)%4==0:
            summ+=1
    else:
        if (b-a)%4!=0:
            summ+=1
else:
    if (b-a)%4==1:
        summ+=1


for i in range(1,len(stra)):
    numa = int(stra[-1*i -1])
    numb = int(strb[-1*i -1])
    
    rem = 0
    cha = 0
    
    if numa==1:
        rem = a%(2**(i+1))
    if numb == 1:
        cha = b%(2**(i+1)) + 1 - 2**i
    
    if (cha+rem)%2==1:
        summ += 2**i

print(summ)

Solution (Python):
A, B = map(int,input().split())
A_non_zero = 0
B_non_zero = 0
if A%2==1:
    A_non_zero = A
    A +=1
if B%2!=1:
    B_non_zero =B
else:
    B +=1
count = (B-A)//2
result =bin(A_non_zero^B_non_zero^count%2)
print(int(result,2))

Solution (Python):
A, B = (int(x) for x in input().split())
def exor(n):
  m = n % 4
  if m == 0:
    return n
  elif m == 1:
    return 1
  elif m == 2:
    return n+1
  else:
    return 0
ans = exor(A-1)^exor(B)
print(ans)

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

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

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

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

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

Solution (Python):


def solve2():
    """解説PDF
    任意の偶数nについて n ^ (n+1) = 1

    この性質は、最下位ビットのみが異なることからわかる。

    たとえば、
    F(0, 6) = 0^1^2^3^4^5^6
            = (0^1)^(2^3)^(4^5)^6
            = 1^1^1^6
    のように計算できる。

    また、排他的論理和の性質として、

    a ^ b = c
    a = c ^ b

    が成り立つので、（両辺に ^b するイメージ。b^b=0 である）

    F(0, B) = F(0, A-1) ^ F(A, B)
    F(A, B) = F(0, A-1) ^ F(0, B)

    が成り立つ。
    """
    A, B = list(map(int, input().split()))

    def calc(a):
        """ F(0, a)を返す。計算量O(1) """
        if a == 0:
            return 0
        elif a == 1:
            return 1

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


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

    """解説
    考え方としては、累積和みたいなかんじ
    「4~8までのxor」は、「0~8までのxor」 から 「0~3までのxor」 を引くかんじ

    A xor B = C のとき、
    A xor C = B であることに着目する

    各桁の1の数を数えれば求まる

    ・1~8のxor
    0000 | 0
    0001 | 1
    0010 | 2
    0011 | 3
    0100 | 4
    0101 | 5
    0110 | 6
    0111 | 7
    1000 | 8
    ----
    1001

    ・各桁の01の周期に着目する
    ・0桁目の周期は2
    ・1桁目の周期は4
    ・2桁目の周期は8
    ・3桁目の周期は16
    """

    def calc(a):
        """ F(0, a)を返す。 計算量O(log(B))? """
        
        
        
        if a <= 0: return 0

        ans = 0
        for i in range(0, 50):
            
            
            
            
            T = 1 << (i+1)

            
            
            cnt = ((a+1)//T) * (T/2)
            
            cnt += max(0, ((a+1)%T) - (T/2))

            
            if cnt%2 == 1:
                ans += 1 << i
        
        return ans

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

if __name__ == "__main__":
    solve2()

Solution (Python):


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

    """解説
    考え方としては、累積和みたいなかんじ
    「4~8までのxor」は、「0~8までのxor」 から 「0~3までのxor」 を引くかんじ

    A xor B = C のとき、
    A xor C = B であることに着目する

    各桁の1の数を数えれば求まる

    ・1~8のxor
    0000 | 0
    0001 | 1
    0010 | 2
    0011 | 3
    0100 | 4
    0101 | 5
    0110 | 6
    0111 | 7
    1000 | 8
    ----
    1001

    ・各桁の01の周期に着目する
    ・0桁目の周期は2
    ・1桁目の周期は4
    ・2桁目の周期は8
    ・3桁目の周期は16
    """

    def calc(a):
        
        
        
        if a <= 0: return 0

        ans = 0
        for i in range(0, 50):
            
            
            
            
            T = 1 << (i+1)

            
            
            cnt = ((a+1)//T) * (T/2)
            
            cnt += max(0, ((a+1)%T) - (T/2))

            
            if cnt%2 == 1:
                ans += 1 << i
        
        return ans

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

if __name__ == "__main__":
    solve()

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

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

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

Solution (Python):
def xy(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())
ans = xy(b) ^ xy(a - 1)
print(ans)

Solution (Python):
def xor(a, b):
    l = len(b)
    za = a.zfill(l)
    ret = ""
    for i in range(l):
        if za[i] == "0" and b[i] == "0":
            ret = ret + "0"
        elif za[i] == "0" and b[i] == "1":
            ret = ret + "1"
        elif za[i] == "1" and b[i] == "0":
            ret = ret + "1"
        else:
            ret = ret + "0"
    return ret

def spxor(n):
    r = ""
    if n % 4 == 1 or n % 4 == 2:
        r = "1" + r
    else:
        r = "0" + r

    k = 1
    while n >= 2 ** k:
        a = n % (2 ** (k + 1))
        if a >= 2 ** k and a % 2 == 0:
            r = "1" + r
        else:
            r = "0" + r
        k += 1
    return r

def to10d(s):
    le = len(s) - 1
    j = len(s) - 1
    re = 0
    while j >= 0:
        re += int(s[j]) * (2 ** (le - j))
        j -= 1
    return re

a, b = map(int, input().split())
if a == 0:
    print(to10d(spxor(b)))
else:
    sa = spxor(a - 1)
    sb = spxor(b)
    print(to10d(xor(sa,sb)))

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


def calc(x):
    x += 1
    res = 0
    for i in range(40):
        p = 1 << (i + 1)
        cnt = (x // p) * (p // 2) + max(0, (x % p) - (p // 2))
        if cnt % 2 == 1:
            res += 1 << i
    return res


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

Solution (Python):
a, b = map(int, input().split())
"""s = bin(a)
t = bin(b)
s = s[2:]
t = t[2:]
cri = len(t)
s = (cri - len(s)) * "0" + s
q = 0
for i in reversed(range(len(s))):
    if i == len(s) - 1:"""



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

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

print(ans)

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

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

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

Solution (Python):

def main():
    
    A,B = map(int,input().split())
    
    point_A = A
    point_B = B
    if A%4 > 0:
        point_A = A - (A%4) + 4
    if B%4 > 0:
        point_B = B - (B%4)

    
    
    ans = 0
    for i in range(A,point_A):
        ans = ans ^ i

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


if __name__ == "__main__":
    main()

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

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


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

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

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


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


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

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

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