0

I've already tried non efficent programming techniques

test.assert_equals(fib(0),0)
test.assert_equals(fib(1),1)
test.assert_equals(fib(2),1)
test.assert_equals(fib(3),2)
test.assert_equals(fib(4),3)
test.assert_equals(fib(5),5)
test.assert_equals(fib(1000),43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875)

1 Answers1

0

This will probably help :

https://www.sanfoundry.com/python-program-print-nth-fibonacci-number-using-dynamic-programming-memoization/

This is a pretty good website.

EDIT :

instead of memoization, we can use another formula :

from math import sqrt
def nthFib(n):
    res = int((((1+sqrt(5))**n)-((1-sqrt(5)))**n)/(2**n*sqrt(5)))
    print(res)
nthFib(12)
Silloky
  • 147
  • 13