PUZZLE PE-002
Even Fibonacci Numbers
Project Euler · Problem 2
Original problem
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
Formal statement
Define
Compute
Hints
Open one at a timeWrite down the parity pattern of consecutive Fibonacci numbers.
Every third term is even.
Solution
Best opened after a real attemptApproach
Parity in the Fibonacci sequence repeats every three terms: odd, even, odd. Therefore every third term is even. If the even-valued terms are written as
Starting from the first even term, this recurrence visits only values that contribute to the sum. It avoids generating and testing the intervening odd Fibonacci numbers while preserving a simple loop.
Code & final result
The original problem is reproduced from Project Euler Problem 2 under CC BY-NC-SA 4.0.