mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 13:31:07 +00:00
Added Solution to Problem 2 in a simple approach
This commit is contained in:
parent
fc3bdb6e12
commit
1ead4e0f2d
20
Project Euler/Problem 02/sol3.py
Normal file
20
Project Euler/Problem 02/sol3.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
'''
|
||||||
|
Problem:
|
||||||
|
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
|
||||||
|
0,1,1,2,3,5,8,13,21,34,55,89,..
|
||||||
|
Every third term from 0 is even So using this I have written a simple code
|
||||||
|
By considering the terms in the Fibonacci sequence whose values do not exceed n, find the sum of the even-valued terms.
|
||||||
|
e.g. for n=10, we have {2,8}, sum is 10.
|
||||||
|
'''
|
||||||
|
"""Python 3"""
|
||||||
|
n = int(input())
|
||||||
|
a=0
|
||||||
|
b=2
|
||||||
|
count=0
|
||||||
|
while 4*b+a<n:
|
||||||
|
c=4*b+a
|
||||||
|
a=b
|
||||||
|
b=c
|
||||||
|
count=count+a
|
||||||
|
print(count+b)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user