Project Euler #2: Even Fibonacci numbers

  • + 1 comment

    sorry for late advice - store the first fibbonachi numbers in memory and go thrue tests $-)

    import functools
    @functools.lru_cache(maxsize=None)
    def fib(n):
        if n<=2:
            return 1
        else:
            return fib(n-1) + fib(n-2)
    
    
    
    n = int(input().strip())
    s=0
    for i in range(3,n,3):
        _ = fib(i)
        if _<=n:
            s+=_
        else:
            break
            
    print(_)
    

    all works on slow but wise Python