Skip to content

Instantly share code, notes, and snippets.

@andrescabana86
Last active January 31, 2019 22:06
Show Gist options
  • Save andrescabana86/739923f15423383809236540c709b535 to your computer and use it in GitHub Desktop.
Save andrescabana86/739923f15423383809236540c709b535 to your computer and use it in GitHub Desktop.
This is the formula I followed up -> Fn = {[(√5 + 1)/2] ^ n} / √5
import math
def fib(n):
return int(round(pow(((1 + math.sqrt(5)) / 2), n) / math.sqrt(5)))
# complexity O(n)
# space O(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment