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, …
By considering the terms in the Fibonacci sequence whose values do not exceed four million,
find the sum of the even-valued terms.
翻译下:就是在斐波那契数列中找到小于4000000的那个数,然后求它之前的所有偶数的和并打印出来
even-valued terms 偶数
odd-valued terms 奇数
Ruby代码:
1 |
def |
输出结果:
1 |
The sum of all even-valued is 4613732 |
近期评论