fork download
  1. """(c) WhiZTiM -------- ionogu(<_at_>)acm.org"""
  2.  
  3. """Very Fast reusable and Dynamic Fibonacci calculator """
  4. class Fibonacci:
  5. def __init__(self):
  6. self.memory = [0, 1, 1]
  7. def compute(self, n):
  8. if n < len(self.memory):
  9. return self.memory[n]
  10. c1 = self.compute(n - 1)
  11. c2 = self.compute(n - 2)
  12. self.memory.append(c1 + c2)
  13. return c1 + c2
  14.  
  15. def solve(limit):
  16. fib = Fibonacci(); rtn = []
  17. for x in range(limit):
  18. n = fib.compute(x)
  19. if n > limit: return rtn
  20. if n % 2 == 0: rtn.append(n)
  21.  
  22. print(sum(solve(4000000)))
Success #stdin #stdout 0.02s 8688KB
stdin
Standard input is empty
stdout
4613732