Project Euler #2: Even Fibonacci numbers

  • + 0 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))