Skip to content

Instantly share code, notes, and snippets.

@OussaZaki
Created June 25, 2017 20:18
Show Gist options
  • Save OussaZaki/6e4e38c85a285e3cf285165ae71262bb to your computer and use it in GitHub Desktop.
Save OussaZaki/6e4e38c85a285e3cf285165ae71262bb to your computer and use it in GitHub Desktop.
Naive implementation of Project Euler #2: Even Fibonacci numbers.
def even_fibonacci_sum(n):
fn_2 = 1 #Fn-2
fn_1 = 1 #Fn-1
sum = 0
while True :
fn = fn_2 + fn_1 #Fn
if fn >= n: return sum
if fn % 2 == 0: sum += fn
fn_2, fn_1 = fn_1, fn
t = int(input().strip())
for i in range(t):
n = int(input().strip())
print(even_fibonacci_sum(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment