-
Notifications
You must be signed in to change notification settings - Fork 110
/
solution.py
37 lines (37 loc) · 820 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# solve function return the integer value calculated
def solve():
left_side=0
if (L+1)%4==0:
ans=2
left_side=L+5
if L%4==0:
ans=2
left_side=L+4
if (L+3)%4==0:
ans=L+1
left_side=L+3
if (L+2)%4==0:
ans=L+1
left_side=L+2
right_side=0
if (R+1)%4==0:
ans=ans^2
right_side=R-3
if (R-2)%4==0:
ans=ans^2
right_side=R-2
if (R-1)%4==0:
ans=ans^(R)
right_side=R-1
if (R%4)==0:
ans=ans^R
right_side=R
diff=(right_side - left_side)/4
if diff%2 != 0 : ans=ans^2
return ans
# input number of questions
T=int(input())
for _ in range(T):
# the inclusive left and right indexes of the segment to query
L,R=map(int,input().split())
print(solve())