-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp050.java
More file actions
34 lines (27 loc) · 794 Bytes
/
p050.java
File metadata and controls
34 lines (27 loc) · 794 Bytes
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
package level02;
import java.util.List;
import org.junit.Test;
import lib.EulerTest;
public class p050 extends EulerTest {
final int N = 1000000;
/**
* Find the number less than N that is the sum of the most consecutive primes.
*/
@Test
public void test() {
List<Integer> primes = primes(N);
int maxNumPrimes = 0;
for (int i : range(primes.size())) {
int numPrimes = 0, sum = 0;
for (int j = i; j < primes.size() && sum < N; j++) {
if (numPrimes > maxNumPrimes && isPrime(sum)) {
maxNumPrimes = numPrimes;
ans = sum;
}
numPrimes++;
sum += primes.get(j);
}
}
check(997651);
}
}