-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLargestPrimeFactor.java
More file actions
31 lines (29 loc) · 880 Bytes
/
LargestPrimeFactor.java
File metadata and controls
31 lines (29 loc) · 880 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.List;
import java.util.ArrayList;
import java.util.Arrays;
public class LargestPrimeFactor {
public long find(long num) {
List<Long> primes = new ArrayList<>(Arrays.asList(2l));
boolean isPrime = true;
for (long i = 3l; i < 1000000l; i += 2l) {
isPrime = true;
for (int j = 0; j < primes.size(); j++) {
if (i % primes.get(j) == 0l) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.println(i);
primes.add(i);
}
}
System.out.println(primes);
return 0l;
}
public static void main(String[] args) {
LargestPrimeFactor lpf = new LargestPrimeFactor();
long num = 13195;
System.out.println(lpf.find(num));
}
}