Created
May 6, 2019 19:27
-
-
Save izanbf1803/399b791364ddb338274f5e5b10f914a6 to your computer and use it in GitHub Desktop.
Fast O(log n) computation of n-th fibonacci number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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