What is the first term in the Fibonacci sequence to contain 1000 digits? Notes: Generator written and saved in projecteuler. Super easy deal. For large fib vals, F(n) = round(phi**n / sqrt(5)) phi**n / sqrt(5) > 10**999 n * log(phi) - .5 * log(5) > 999 * log(10) """ from math import log from projecteuler import fibonacci if __name__ == '__main__': # Generator way for (i, f) in enumerate(fibonacci()): if f / 10**999: break print 'the {}-th term is\n\n{}\n'.format(i + 1, f) # Math way phi = 1.6180 n = (999. * log(10.) + .5 * log(5)) / log(phi) print 'By Great Maths we have i = {}'.format(n)
from projecteuler import fibonacci L = 30 # Limit is expressed as 2^L print "Project Euler 301 Solution =", fibonacci(L + 2)
Notes: Generator written and saved in projecteuler. Super easy deal. For large fib vals, F(n) = round(phi**n / sqrt(5)) phi**n / sqrt(5) > 10**999 n * log(phi) - .5 * log(5) > 999 * log(10) """ from math import log from projecteuler import fibonacci if __name__ == '__main__': # Generator way for (i, f) in enumerate(fibonacci()): if f / 10**999: break print 'the {}-th term is\n\n{}\n'.format(i + 1, f) # Math way phi = 1.6180 n = (999. * log(10.) + .5 * log(5)) / log(phi) print 'By Great Maths we have i = {}'.format(n)
from projecteuler import fibonacci L = 30 # Limit is expressed as 2^L print "Project Euler 301 Solution =", fibonacci(L+2)