Problem 25. 1000-digit Fibonacci number

Description

#!/usr/bin/python

cfibCache = {}

def cfib(n):
try:
return cfibCache[n]
except KeyError:
if n == 0 or n == 1:
cfibCache[n] = 1
return 1
else:
cfibCache[n] = cfib(n-1) + cfib(n-2)
return cfibCache[n]

n = 1
f = 0
while (len(str(f)) < 1000): f = cfib(n) n+=1; print n

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>