We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6ec53de commit f55fe6eCopy full SHA for f55fe6e
βπ P5/11778.py
@@ -0,0 +1,28 @@
1
+n, m = map(int, input().split())
2
+p = 1000000007
3
+
4
+def gcd(a, b):
5
+ if a % b == 0: return b
6
+ return gcd(b, a%b)
7
8
+gcd_n_m = gcd(n, m)
9
10
+fibo = {}
11
+def fibonacci(n) :
12
+ if n == 0:
13
+ return 0
14
+ if n == 1 or n == 2:
15
+ fibo[n] = 1
16
+ return fibo[n]
17
+ if n in fibo:
18
19
20
+ if n & 1:
21
+ k = (n+1)//2
22
+ fibo[n] = (fibonacci(k)*fibonacci(k) + fibonacci(k-1) * fibonacci(k-1)) % p
23
+ else :
24
+ k = n//2
25
+ fibo[n] = (2*fibonacci(k-1) + fibonacci(k)) * fibonacci(k) % p
26
27
28
+print(fibonacci(gcd_n_m))
0 commit comments