-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimeFactor.java
More file actions
34 lines (33 loc) · 1.19 KB
/
Copy pathprimeFactor.java
File metadata and controls
34 lines (33 loc) · 1.19 KB
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
/**
* Created by theartiste on 1/4/16.
*/
public class primeFactor {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
boolean isPrime = true;
int numberOfFactors = 0;
long largestPrimeFactor = 1;
long theNumber = 34567234;
long bound = (long) Math.sqrt(theNumber);
for (int i = 1; i <= bound; i++) {
if ((theNumber%i) == 0) {
System.out.println("factor : " + i);
for (int j = 2; j < i/2; j++) {
if ((i%j) == 0) {
System.out.println("composite factor : " + i);
isPrime = false;
break;
}
}
System.out.println(isPrime);
if(isPrime) {
if (i > largestPrimeFactor) largestPrimeFactor = i;
}
isPrime = true;
}
}
System.out.println("The largest prime factor of " + theNumber + " is " + largestPrimeFactor);
long endTime = System.currentTimeMillis();
System.out.println("took " + (endTime - startTime) + " millisec.");
}
}