-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem003.java
More file actions
28 lines (28 loc) · 803 Bytes
/
Problem003.java
File metadata and controls
28 lines (28 loc) · 803 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
import java.util.ArrayList;
/**
* Finds the largest prime factor of num
* @author Sean Titus
* @version 1.0
*/
public class Problem3 {
/**
* Main class to find largest prime
* @param args Command line argument not used
*/
public static void main(String[] args) {
long num = 600851475143L;
PrimeGen pg = new PrimeGen((int)(Math.sqrt(num)));
ArrayList<Integer> divisors = new ArrayList<Integer>();
ArrayList<Integer> primes = pg.getPrimesList();
int i = 0;
while (num > 1) {
int prime = primes.get(i);
while (num % prime == 0) {
num /= prime;
divisors.add(prime);
}
i++;
}
System.out.println(divisors.get(divisors.size()-1));
}
}