You are viewing a single comment's thread. Return to all comments →
This is my solution in python but it failed test case 3, it happens for a bigger a number of input because of time out.
if name == 'main': t = int(input().strip()) for t_itr in range(t): n = int(input().strip()) fib1 = 0 fib2 = 1 count = 0 inp = 10000 num = set() num2 = set() while count < inp: if fib1 < n and fib1 % 2 == 0: num.add(fib1) fib3 = fib2+fib1 fib1, fib2 = fib2, fib3 count += 1 print(sum(num))
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 →
This is my solution in python but it failed test case 3, it happens for a bigger a number of input because of time out.
if name == 'main': t = int(input().strip()) for t_itr in range(t): n = int(input().strip()) fib1 = 0 fib2 = 1 count = 0 inp = 10000 num = set() num2 = set() while count < inp: if fib1 < n and fib1 % 2 == 0: num.add(fib1) fib3 = fib2+fib1 fib1, fib2 = fib2, fib3 count += 1 print(sum(num))