Skip to content

Instantly share code, notes, and snippets.

@izanbf1803
Created May 6, 2019
Embed
What would you like to do?
Fast O(log n) computation of n-th fibonacci number.
import numpy as np
n = int(input())
M = np.matrix([[1,1],[1,0]], dtype="object")
ans = (M**n)[0,0]
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment