-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3.java
More file actions
39 lines (27 loc) · 718 Bytes
/
Problem3.java
File metadata and controls
39 lines (27 loc) · 718 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
32
33
34
35
36
37
38
39
import java.util.PriorityQueue;
import java.util.Comparator;
public class Problem3 {
public static void main(String[] args){
long num = 600851475143L;
long result = 2;
PriorityQueue<Long> q = new PriorityQueue<Long>(1, new Comparator<Long>(){
public int compare(Long arg0, Long arg1) {
return arg0.compareTo(arg1) * -1;
}
});
while( num > 1 ){
while( num % result == 0){
q.offer(result);
num /= result;
}
result += 1;
}
System.out.println(q.poll());
}
public static boolean isPrime(long x){
if(x == 2) return true;
if(x == 3) return true;
if(x < 2) return false;
return ((x % 2 != 0) && (x % 3 != 0));
}
}