002. 斐波那契数列中的偶数
2014-05-21 17:09
190 查看
Problem 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:
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.
斐波那契数列中的每一项被定义为前两项之和。要求找出该数列中值为不超过 4 百万的偶数的项之和。
我的python代码:
first = 1
last =2
sum = 2
while 1 :
last = first + last;
first = last - first;
if last<4000000 :
if last%2==0:
sum+=last
else:
break;
print sum
你知道有更好的可以留言啊,大家互相学习啊!
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.
斐波那契数列中的每一项被定义为前两项之和。要求找出该数列中值为不超过 4 百万的偶数的项之和。
我的python代码:
first = 1
last =2
sum = 2
while 1 :
last = first + last;
first = last - first;
if last<4000000 :
if last%2==0:
sum+=last
else:
break;
print sum
你知道有更好的可以留言啊,大家互相学习啊!
相关文章推荐
- 欧拉计划002. 斐波那契数列中的偶数
- 欧拉计划之题目2:在斐波那契数列中,找出4百万以下的项中值为偶数的项之和。
- 判断斐波那契数列中的某项是不是偶数
- 题目2:在斐波那契数列中,找出4百万以下的项中值为偶数的项之和。
- 题目2:在斐波那契数列中,找出4百万以下的项中值为偶数的项之和。
- 在斐波那契数列中,找出4百万以下的项中值为偶数的项之和。
- 欧拉工程第2题 在斐波那契数列中,找出4百万以下的项中值为偶数的项之和
- 题目2:在斐波那契数列中,找出4百万以下的项中值为偶数的项之和。
- 一个斐波那契数列的前10项为:1, 2, 3, 5, 8, 13, 21, 34, 55, 89,对于一个最大项的值不超过n的斐波那契数列,求值为偶数的项的和。
- 斐波那契数列
- LightOJ 1259 - Goldbach`s Conjecture (分解偶数为两个素数之和)
- 剑指offer 斐波那契数列
- 12C-OCP升级1z-060-002
- 【追求进步】斐波那契数列
- LightOJ1336 Sigma Function(约数和为偶数的个数)
- 求解斐波那契数列的动态规划方法
- 刷题第一天:南邮NOJ斐波那契数列
- 使用两个线程交替打印0到100的奇数和偶数
- 调整数组顺序使奇数位于偶数前面
- [Study Notes][002][gstreamer] 的环境变量设定