-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectEuler2.java
More file actions
41 lines (38 loc) · 1.1 KB
/
projectEuler2.java
File metadata and controls
41 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Author: Sreenath T V
* https://www.hackerrank.com/contests/projecteuler/challenges/euler002
*/
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) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int T;
Scanner kbd = new Scanner(System.in);
T = kbd.nextInt();
long current = 2;
long previous = 1;
long sum = 2;
long arr[] = new long[T];
long temp = 0;
for (int i = 0; i < T; i++) {
arr[i] = kbd.nextLong();
}
for (int i = 0; i < T; i++) {
temp = current + previous;
while (temp < arr[i]) {
sum += (temp % 2 == 0) ? temp : 0;
previous = current;
current = temp;
temp = current + previous;
}
System.out.println(sum);
current = 2;
previous = 1;
sum = 2;
}
}
}