Problem 2 - Even Fibonacci Numbers

Author

Vincent Clemson

Published

January 15, 2026

Modified

January 24, 2026

Mirissa, Sri Lanka - April 26th, 2025

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with \(1\) and \(2\), the first \(10\) terms will be: \[1, 2, 3, 5, 8, 13, 21, 34, 55, 89, \dots\]

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

https://projecteuler.net/problem=2

Thoughts

This is straightforward. We can calculate the Fibonacci sequence up to the value of 4 million. Then, we can sum all even numbers in the sequence.

R

Answer 1

Code
y <- c(1, 2)
while (rev(y)[1] < 4e6) {
  y <- c(y, sum(rev(y)[1:2]))
}
sum(y[y %% 2 == 0])
[1] 4613732

Python

Answer 1

Back to top

Reuse

© 2023-2026 Vincent Clemson | This post is licensed under <a href='http://creativecommons.org/licenses/by-nc-sa/4.0/' target='_blank'>CC BY-NC-SA 4.0</a>

Citation

For attribution, please cite this work as:
Clemson, Vincent. 2026. “Problem 2 - Even Fibonacci Numbers.” January 15, 2026. https://prncevince.xyz/euler/problem/0002.html.