We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b6bdb2f commit c645383Copy full SHA for c645383
1 file changed
Hackerearth/June_Circuits_2019/functionValue_v1.py
@@ -0,0 +1,26 @@
1
+def recurEven(n):
2
+ if n == 1:
3
+ return (1)
4
+ elif n == 2:
5
6
+ else:
7
+ return (2*recurEven(n-1) - recurEven(n-2) + 2)
8
+
9
+def recurOdd(n):
10
+ if n==1:
11
12
+ elif n==2:
13
14
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