project欧拉第二题

http://projecteuler.net/index.php?section=problems&id=2

projecteuler.net第二题
Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million.
求Fibonacci数列中小于4百万的偶数之和.

答案:4613732


python code:

    def fibonacci(x):
        a,b=0,1
        while a<x:
            yield a
            a,b=b,a+b
    print sum(x for x in fibonacci(4000000) if x%2==0)

你可能感兴趣的:(.net,PHP,python)