Skip to content

Instantly share code, notes, and snippets.

@izanbf1803
Created May 6, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izanbf1803/399b791364ddb338274f5e5b10f914a6 to your computer and use it in GitHub Desktop.
Save izanbf1803/399b791364ddb338274f5e5b10f914a6 to your computer and use it in GitHub Desktop.
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