Skip to content

Instantly share code, notes, and snippets.

@cosmin
Created March 30, 2009 09:52
Show Gist options
  • Save cosmin/87719 to your computer and use it in GitHub Desktop.
Save cosmin/87719 to your computer and use it in GitHub Desktop.
# Constant time Fib using Binet's formula
def fib(n):
q = (1 + math.sqrt(5)) / 2
return int(((q ** n) - (1 - q) ** n) / math.sqrt(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment