You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a = 0; a < t; a++){ long n = in.nextLong(); long first=1; long second=2; long sum=0,third=0; while(third<n) { if(second%2==0){ sum=sum+second; } third=first+second; first=second; second=third; } System.out.println(sum); } }
}
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 →
}