-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem027.java
More file actions
29 lines (29 loc) · 900 Bytes
/
Problem027.java
File metadata and controls
29 lines (29 loc) · 900 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
public class Problem27 {
public static void main(String[] args) {
PrimeGen pg = new PrimeGen(10000000);
int[] primes = pg.getFullPrimes();
int longest = 0;
int product = 0;
for (int a = -999; a < 1000; a++) {
for (int b = -999; b < 999; b++) {
int n = 0;
int chain = 0;
boolean loop = true;
while (loop) {
int val = n * n + a * n + b;
if (val >= 0 && primes[val] != 0) {
chain++;
n++;
} else {
loop = false;
}
}
if (chain > longest) {
longest = chain;
product = a * b;
}
}
}
System.out.println(product);
}
}