Project Euler - Problem 2
2012-05-05 07:46
239 查看
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.
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
def SumOfEvenValuedFibbonacciTerms(limit): sum = 0 a = b = 1 while b < limit: if not b % 2: sum += b a, b = b, a + b return sum
相关文章推荐
- Project Euler:Problem 55 Lychrel numbers
- Project Euler :Problem 54 Poker hands
- [Project Euler]加入欧拉 Problem3
- [Project Euler] Problem 6
- [Project Euler] Problem 16
- [Project Euler]Problem 8
- Project Euler: Problem 14 Longest Collatz sequence
- Project Euler:Problem 23 Non-abundant sums
- Project Euler:Problem 34 Digit factorials
- [Project Euler] Problem 20
- Project Euler – Problem 14
- Project Euler:Problem 42 Coded triangle numbers
- [Project Euler] Problem 7
- [Project Euler] Problem 22
- Project Euler:Problem 15 Lattice paths
- Project Euler:Problem 24 Lexicographic permutations
- Project Euler:Problem 35 Circular primes
- Project Euler:Problem 52 Permuted multiples
- [Project Euler] Problem 21
- Project Euler:Problem 78 Coin partitions