Project Euler Homework
Functions

025.cpp File Reference

What is the first term in the Fibonacci sequence to contain 1000 digits? The Fibonacci sequence is defined by the recurrence relation: More...

Go to the source code of this file.

Functions

int main ()

Detailed Description

What is the first term in the Fibonacci sequence to contain 1000 digits? The Fibonacci sequence is defined by the recurrence relation:

Fn = Fn−1 + Fn−2 , where F1 = 1 and F2 = 1.

Hence the first 12 terms will be:

The 12th term, F12, is the first term to contain three digits.

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

Definition in file 025.cpp.


Function Documentation

int main ( )

General formula:

\[ f_n = \frac{1}{\sqrt{5}}\left[\left(\frac{1+\sqrt{5}}{2} \right)^n - \left(\frac{1-\sqrt{5}}{2} \right)^n \right] \]

when n is large,

\[ \left(\frac{1-\sqrt{5}}{2} \right)^n \sim 0 \]

Hence

\[ f_n = \frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2} \right)^n \]

\[ f_n >= 10^{999} \Rightarrow n >= 4781.86 \]

Therefore $ n = 4782 $

Definition at line 37 of file 025.cpp.

 All Classes Files Functions Variables