-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem047.java
More file actions
31 lines (31 loc) · 942 Bytes
/
Problem047.java
File metadata and controls
31 lines (31 loc) · 942 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
import java.util.ArrayList;
import java.util.HashSet;
public class Problem047 {
private static ArrayList<Integer> primes;
private static boolean hasFour(int num) {
HashSet<Integer> factors = new HashSet<Integer>();
int i = 0;
int j = num;
while (primes.get(i) <= num / 2 && primes.get(i) <= j) {
while (j % primes.get(i) == 0) {
j /= primes.get(i);
factors.add(primes.get(i));
}
i++;
}
return factors.size() == 4;
}
public static void main(String[] args) {
PrimeGen pg = new PrimeGen(1000000);
primes = pg.getPrimesList();
boolean found = false;
int i = 2;
while (!found) {
if (hasFour(i) && hasFour(i+1) && hasFour(i+2) && hasFour(i+3)) {
found = true;
System.out.println(i);
}
i++;
}
}
}