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.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- > 0) {
long n = in.nextLong();
long a = 1, b = 2, sum = 0;
while (b <= n) {
if (b % 2 == 0) {
sum += b;
}
long temp = a + b;
a = b;
b = temp;
}
System.out.println(sum);
}
in.close();
}
}
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 →
import java.util.Scanner;
public class Solution {
}