I was trying to avoid a recursive function to solve this problem, so I took an iterative approach. I was originally doing a memoized recursive function but kept hitting max recursive depth. I also had strict memory goals so you will see me keeping the array as small as I can during the looping process only keeping 2-3 values in the array at any time.
def fib(n):
fibs = [1, 1] # my starting array
for f in range(2, n):
fibs.append(fibs[-1] + fibs[-2]) # appending the new fib number
del fibs[0] # removing the oldest number
return fibs[-1] # returning the newest fib
print(fib(6000000))
Getting the 6 millionth fibonacci number takes about 282 seconds on my machine while the 600k fibonacci takes only 2.8 seconds. I was unable to obtain such large fibonacci numbers with a recursive function, even a memoized one.