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.
Project Euler #2: Even Fibonacci numbers
Project Euler #2: Even Fibonacci numbers
Sort by
recency
|
635 Discussions
|
Please Login in order to post a comment
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]
import java.util.Scanner;
public class Solution {
}
def sum_fib(n): a,b= 1,2 even_sum = 0 while b<=n: if b%2==0: even_sum +=b a,b=b,a+b return even_sum
if name == 'main': t = int(input().strip())
For the sake of discussion and explanation of the question, I am providing detailed comments within the code. Please refer to these comments for a clear understanding of the logic and functionality of the code.
**//1,1,2,3,5,8,13,21,34,55,89,144 //using the knowledge that after every two terms comes an even term //Sum of two odds is an even(two oods then an even) ** int main(){ int t; cin >> t; for(int a0 = 0; a0 < t; a0++){ long n; cin >> n; long a1=1; long a2=1;
}