You are viewing a single comment's thread. Return to all comments →
import math import os import random import re import sys
def even_fib_sum(n): a, b = 1, 2 total = 0 while b <= n: if b % 2 == 0: total += b a, b = b, a + b return total
if name == 'main': t = int(input().strip()) for t_itr in range(t): n = int(input().strip()) print(even_fib_sum(n))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
import math import os import random import re import sys
def even_fib_sum(n): a, b = 1, 2 total = 0 while b <= n: if b % 2 == 0: total += b a, b = b, a + b return total
if name == 'main': t = int(input().strip()) for t_itr in range(t): n = int(input().strip()) print(even_fib_sum(n))