-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP3.java
32 lines (27 loc) · 820 Bytes
/
P3.java
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
import java.util.Scanner;
import java.util.LinkedList;
public class P3 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter N: ");
long N = s.nextLong();
LinkedList<Integer> factors = new LinkedList<Integer>();
int i = 2, largest = 0;
while (N > 1) {
if (N % i == 0) {
factors.add(i);
N /= i;
}
i++;
}
boolean prime = true;
for (int a : factors) {
prime = true;
for (int b = 2; b < a; b++) {
if (a % b == 0) prime = false;
}
if (prime) largest = a;
}
System.out.println(largest);
}
}