Skip to content

Instantly share code, notes, and snippets.

@SahilKadam
Created October 13, 2016 15:17
Show Gist options
  • Save SahilKadam/48ac192fa0d2f2a0363daf293bf9895a to your computer and use it in GitHub Desktop.
Save SahilKadam/48ac192fa0d2f2a0363daf293bf9895a to your computer and use it in GitHub Desktop.
This question expands on our earlier Fibonacci Lite challenge. While the goal of Fibonacci Lite was to understand recursion, this challenge is about solving problems efficiently with dynamic programming. The difference in this challenge is that each test case will consist of many inputs instead of just one. Furthermore, we're allowing larger val…
from math import sqrt
def fibo(n):
return (((1+sqrt(5))**n - (1-sqrt(5))**n)/(2**n*sqrt(5)))
while True:
try:
n = int(input().strip())
print (int(fibo(n)))
except(EOFError):
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment