projecteuler---->problem:2

题目:

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.

翻译:

Fibonacci数列的每后一项都是前面两项的和,若开始的头两项是1和2,那么前10个项就是:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

请求出以上Fibonacci数列中不超过400,0000的所有偶数的和。

解答:

sum,a,b,c=2,1,2,3
while(1):
	c=a+b
	a = b
	b = c
	if c > 4000000:
		break
	if c % 2 == 0:
		 sum += c
print sum
	


你可能感兴趣的:(python)