-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestPrimeFactor.java
More file actions
34 lines (31 loc) · 901 Bytes
/
Copy pathLargestPrimeFactor.java
File metadata and controls
34 lines (31 loc) · 901 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
/** Project Euler.net
*
* PROBLEM 3:
* The prime factors of 13195 are 5, 7, 13 and 29.
*
* What is the largest prime factor of the number 600851475143 ?
*
* ANSWER:
* The largest prime factor is: 906609
*
* @author
* Natalie Kerby :: ndkerby@gmail.com
*/
import math.MATH;
import java.util.*;
public class LargestPrimeFactor {
public static final Long NUMBER = 600851475143L;
public static void main(String[] args) {
Long[] factors = MATH.factors(NUMBER);
long largest_prime = 1;
for(int index = 0; index < factors.length; index++){
boolean isPrime = MATH.isPrime(factors[index]);
if(isPrime){
if (factors[index] > largest_prime) {
largest_prime = factors[index];
}
}
}
System.out.println("The largest prime factor is: " + largest_prime);
}
}