-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem5.java
More file actions
executable file
·63 lines (52 loc) · 1.34 KB
/
Problem5.java
File metadata and controls
executable file
·63 lines (52 loc) · 1.34 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.ArrayList;
import java.util.List;
/**
* Problem5
*/
public class Problem5 {
public static void main(String[] args) {
int k = 20;
int N = 1;
int i = 1;
boolean check = true;
int limit = (int) Math.sqrt(k);
ArrayList<Integer> primes = genPrimes(k);
int[] e = new int[primes.size()+1];
for (Integer p: primes) {
e[i] = 1;
if (check) {
if (p <= limit) {
e[i] = (int) Math.floor(Math.log(k) / Math.log(p));
} else {
check = false;
}
}
N *= Math.pow(p, e[i]);
i++;
}
System.out.println(N);
}
/**
* Generate primes until 'n' value.
*/
private static ArrayList<Integer> genPrimes(int n) {
ArrayList<Integer> primes = new ArrayList<>();
int num = 2;
int status = 1;
for (int i = 3; i <= n && num<=n;) {
for(int j=2; j<=Math.sqrt(num);j++){
if (num%j == 0) {
status = 0;
break;
}
}
if (status != 0) {
primes.add(num);
i++;
}
status = 1;
num++;
}
return primes;
}
}