-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay100.java
More file actions
30 lines (27 loc) · 841 Bytes
/
Day100.java
File metadata and controls
30 lines (27 loc) · 841 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
import java.util.*;
public class Day100 {
public static List<Integer> uniquePrimeFactors(int N) {
List<Integer> factors = new ArrayList<>();
while (N % 2 == 0) {
if (!factors.contains(2))
factors.add(2);
N /= 2;
}
for (int i = 3; i <= Math.sqrt(N); i += 2) {
while (N % i == 0) {
if (!factors.contains(i))
factors.add(i);
N /= i;
}
}
if (N > 2) {
factors.add(N);
}
return factors;
}
public static void main(String[] args) {
int N = 10;
List<Integer> primeFactors = uniquePrimeFactors(N);
System.out.println("Unique prime factors of " + N + " are: " + primeFactors);
}
}