Created
June 25, 2017 20:18
-
-
Save OussaZaki/6e4e38c85a285e3cf285165ae71262bb to your computer and use it in GitHub Desktop.
Naive implementation of Project Euler #2: Even Fibonacci numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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