-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay17.java
More file actions
26 lines (24 loc) · 708 Bytes
/
Day17.java
File metadata and controls
26 lines (24 loc) · 708 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
import java.util.*;
public class PrimeFactorization {
public static List<Long> primeFactors(long n) {
List<Long> factors = new ArrayList<>();
while (n % 2 == 0) {
factors.add(2L);
n /= 2;
}
for (long i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
factors.add(i);
n /= i;
}
}
if (n > 2) factors.add(n);
return factors;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long N = sc.nextLong();
List<Long> result = primeFactors(N);
System.out.println(result);
}
}