aboutsummaryrefslogtreecommitdiff
path: root/entries/Tarcisio-Teixeira/fib.py
blob: a73cdd2387ecfd3c16775104dccae89de4e8af46 (plain) (blame)
1
2
3
4
5
def fib(n,arr={},v =-1):
    if v>=0:
        arr[n]=v
        return v
    return arr[n] if n in arr.keys() else fib(n, arr, (2*n*n*n - 9*n*n+13*n)//6 if  n <= 3 else fib(n//2-1,arr)*fib(n-n//2,arr) + fib(n//2,arr)*fib(n-n//2+1,arr))