I am trying to find the last digit of Big Fibonacci numbers, my script can count them and find the last digit fast but when I try to compute numbers from 1000 I get RecursionError.
Here is my scrip:
cache = {}
def last_digit_of_fibonacci_number(n):
assert 0 <= n <= 10 ** 7
if n in cache:
return cache[n]
if n == 1 or n == 2:
return 1
elif n == 0:
return 0
else:
result = (last_digit_of_fibonacci_number(n - 1) + last_digit_of_fibonacci_number(n - 2)) % 10
cache[n] = result
return result
any ideas of how to fix my issue without resetting the recursion limit using setrecursionlimit()?