Project Euler 2
Project Euler 2
题目
Even Fibonacci numbers
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:
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
解决方案
直接依照递推式$F(i)=F(i-1)+F(i-2)$进行递推即可,时间复杂度为对数级别。
代码
1 | N = 4 * 10 ** 6 |