Here’s problem twenty five:

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

This was pretty simple, all we need to do is generate Fibonacci terms and check the length of each one. We also need a counter to keep track of what term we’re on.

a = b = n = 1
counter = 2
while len(str(n)) != 1000:
counter += 1
n = a + b
a, b = b, n
print(counter)

*a*, *b*, and *n* are variables used to generate the Fibonacci sequence. Since Project Euler defines the first term of the Fibonacci sequence as 1 rather than 0, we initialize the counter to 2, since the first term we calculate (2) will be the 3rd term. The rest is self-explanatory.

*Answer: 4782*

### Like this:

Like Loading...

*Related*

Tags: fibonacci

## Leave a Reply