Skip to main content

Euler 0028

The Problem:

What is the first Fibonacci number with 1000 digits?

Considerations and Approach:

This is somewhat trivial with Python since it can store a 1000 digit number with relative ease, and we don't need to run a super efficient Fibonacci algorithm or store many numbers at all.

The Code:

fib_1 = 1
fib_2 = 2
digits_to_find = 1000

#Start at index of 4 because we already have 1,1,2
running_count = 4

#keep going until the next fib digit length is greater than or equal to the digit to find.
while len(str(fib_1 + fib_2)) < digits_to_find:
    fib = fib_1 + fib_2
    fib_1 = fib_2
    fib_2 = fib
    running_count += 1

print(running_count)