Skip to content

Commit 92cbe09

Browse files
authored
Merge pull request TheAlgorithms#275 from girijamanojkumarreddy/master
Added Solution to Problem 2 in a simple approach
2 parents fc3bdb6 + 1ead4e0 commit 92cbe09

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Project Euler/Problem 02/sol3.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
Problem:
3+
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
4+
0,1,1,2,3,5,8,13,21,34,55,89,..
5+
Every third term from 0 is even So using this I have written a simple code
6+
By considering the terms in the Fibonacci sequence whose values do not exceed n, find the sum of the even-valued terms.
7+
e.g. for n=10, we have {2,8}, sum is 10.
8+
'''
9+
"""Python 3"""
10+
n = int(input())
11+
a=0
12+
b=2
13+
count=0
14+
while 4*b+a<n:
15+
c=4*b+a
16+
a=b
17+
b=c
18+
count=count+a
19+
print(count+b)
20+

0 commit comments

Comments
 (0)