We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
lst=[1,2]
t = int(input().strip())
for a0 in range(t):
n = int(input().strip())
for i in range(2,n):
nextt=lst[i-1]+lst[i-2]
if nextt>n:
break
else:
lst.append(nextt)
e=[j for j in lst if j%2==0]
print(sum(e))
lst=[1,2]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
lst=[1,2] t = int(input().strip()) for a0 in range(t): n = int(input().strip()) for i in range(2,n): nextt=lst[i-1]+lst[i-2] if nextt>n: break else: lst.append(nextt) e=[j for j in lst if j%2==0] print(sum(e)) lst=[1,2]