I just started learning algorithms and I am stuck with the problem of finding a huge Fibonacci number. My example input is 5949. The output should be calculated in less than 5 seconds.
Here is my attempt:
def calc_fib(n):
if n < 0:
print ("Error. Bad input")
elif n <= 2:
return 1
else:
F = []
for i in range (2,n):
F[i] = F[i-1]+F[i-2]
return F[n]
n = int(input())
print(calc_fib(n))
But I get an error on line with arrays: IndexError: list index out of range