Even Fibonacci Numbers¶
There's a lot to learn about the Fibonacci numbers, and this will not be the last time we see them in a Project Euler problem, but for now this problem keeps it relatively simple.
Since this is a SageMath notebook, we'll use its functionality so we can keep our code simple like the problem.
In [1]:
sum(n for n in fibonacci_xrange(1, 4000000) if n % 2 == 0)
Out[1]:
4613732
Even without SageMath, it's easy to implement our own generator of the sequence up to $n$.
In [2]:
def fib(n):
a = 0
b = 1
while a <= n:
yield a
a, b = b, a + b
Relevant sequences¶
Copyright (C) 2025 filifa¶
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license and the BSD Zero Clause license.