Project Euler Problem 025


The Fibonacci sequence is defined by the recurrence relation:

\begin{align} F_{n} = F_{n−1} + F_{n−2},\ where\ F_{1} = 1\ and\ F_{2} = 1. \end{align}

Hence the first 12 terms will be:

Unsupported math environment "flushleft"

The 12th term, $F_{12}$, is the first term to contain three digits.

What is the first term in the Fibonacci sequence to contain 1000 digits?


In a language like Python where you can handle numbers of 1000 digits easily then:

if __name__ == '__main__':
    i1 = 1
    i2 = 1
    index = 2
    while len(str(i2)) < 1000:
        index += 1
        i1, i2 = (i2, i1 + i2)
    print("The result is:", index)

The Python file is available for download here.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License