forked from Mrinank-Bhowmick/python-beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.py
More file actions
16 lines (15 loc) · 749 Bytes
/
2.py
File metadata and controls
16 lines (15 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Even Fibonacci numbers | https://projecteuler.net/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.
# -------------------------------------------------------------------------------
F = lambda n: [
((pow(2 << x, x + 1, (4 << 2 * x) - (2 << x) - 1) % (2 << x)) if x >= 0 else None)
for x in range(2, n + 2)
]
print(sum([x for x in F(32) if x % 2 == 0]))