-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem050.java
More file actions
33 lines (31 loc) · 1.09 KB
/
Problem050.java
File metadata and controls
33 lines (31 loc) · 1.09 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
import java.util.ArrayList;
public class Problem50 {
public static void main(String[] args) {
PrimeGen pg = new PrimeGen(1000000);
ArrayList<Integer> primes = pg.getPrimesList();
int longestChain = 0;
int longPrime = 0;
for (int i = primes.size() - 1; i > -1; i--) {
int j = 0;
boolean found = false;
while (j < i && found == false) {
int total = 0;
int chain = 0;
int k = j;
while (k < i && total < primes.get(i)) {
total += primes.get(k);
chain++;
if (total == primes.get(i) && chain > longestChain) {
found = true;
longestChain = chain;
longPrime = primes.get(i);
System.out.println(primes.get(i) + ": " + chain);
}
k++;
}
j++;
}
}
System.out.println(longPrime);
}
}