Skip to content

Instantly share code, notes, and snippets.

@OussaZaki
Created June 28, 2017 16:57
Show Gist options
  • Save OussaZaki/a6df6318ba5f87943ee7c41c2aeb9c3b to your computer and use it in GitHub Desktop.
Save OussaZaki/a6df6318ba5f87943ee7c41c2aeb9c3b to your computer and use it in GitHub Desktop.
Sum of the even Fibonacci numbers using preprocessing.
from bisect import bisect
even_fibs = [2, 8, 34, 144, 610, 2584, 10946, 46368, 196418, 832040, 3524578, 14930352, 63245986, 267914296, 1134903170,
4807526976, 20365011074, 86267571272, 365435296162, 1548008755920, 6557470319842, 27777890035288,
117669030460994, 498454011879264, 2111485077978050, 8944394323791464, 37889062373143906]
t = int(input().strip())
for i in range(t):
N = int(input().strip())
print(sum(even_fibs[:bisect(even_fibs, N)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment