Skip to content

Instantly share code, notes, and snippets.

@poacosta
Last active February 19, 2023 15:33
Show Gist options
  • Save poacosta/2b653caf620f5de1733eba70def9d104 to your computer and use it in GitHub Desktop.
Save poacosta/2b653caf620f5de1733eba70def9d104 to your computer and use it in GitHub Desktop.
n-th fibonacci with n up to 2_000_000
from numpy import matrix
def fib(n):
return (matrix(
'0 1; 1 1' if n >= 0 else '-1 1; 1 0', object
) ** abs(n))[0, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment