Nth Fibonacci number for n as big as 10^19?
问题 I am trying to make a program to find the nth Fibonacci number for 1 < n < 10^19. Here is my code using dynamic programming. memo = {} def fib(n): if n in memo: return memo[n] if n <= 2: f = 1 else: f = fib(n-1) + fib(n-2) memo[n]=f return f print fib(input()) % 1000000007 My code does not seem to work for large numbers. I get invalid response error. Any suggestions? 回答1: Getting the Nth fibonacci number when N is 10^19 is not goign to work if you do it the naive way (at least i would guess