# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445755 | hamerin | Phibonacci (kriii2_P) | Pypy 3 | 61 ms | 18328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
M = int(1e9 + 7)
mod = M**3
def ext_euc(a, b):
if b == 0:
return (a, 1, 0)
g, x, y = ext_euc(b, a % b)
return (g, y, x-(a//b)*y)
def matmul(l, r):
return [[(l[0][0]*r[0][0]+l[0][1]*r[1][0]) % mod, (l[0][0]*r[0][1]+l[0][1]*r[1][1]) % mod],
[(l[1][0]*r[0][0]+l[1][1]*r[1][0]) % mod, (l[1][0]*r[0][1]+l[1][1]*r[1][1]) % mod]]
def fibo(n):
if n == -1:
return 1
base = [[1, 1], [1, 0]]
target = [[1, 0], [0, 1]]
while n:
if n % 2:
target = matmul(target, base)
base = matmul(base, base)
n //= 2
return target[0][1]
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |