Skip to content

Commit c645383

Browse files
committed
compute the function value - version 1 Non-optimal solution
1 parent b6bdb2f commit c645383

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def recurEven(n):
2+
if n == 1:
3+
return (1)
4+
elif n == 2:
5+
return (1)
6+
else:
7+
return (2*recurEven(n-1) - recurEven(n-2) + 2)
8+
9+
def recurOdd(n):
10+
if n==1:
11+
return (1)
12+
elif n==2:
13+
return (1)
14+
else:
15+
return (3*recurOdd(n-2))
16+
17+
def functionValue(L,R,P):
18+
U = R-L+1
19+
fvalues = [recurEven(L+i) if (L+i)%2==0 else recurOdd(L+i) for i in range(U)]
20+
return (sum(fvalues)%P)
21+
22+
if __name__ == '__main__':
23+
T,P = list(map(int,input().strip().split()))
24+
for _ in range(T):
25+
L,R = list(map(int,input().strip().split()))
26+
print (functionValue(L,R,P))

0 commit comments

Comments
 (0)