-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem7.java
More file actions
40 lines (31 loc) · 946 Bytes
/
Problem7.java
File metadata and controls
40 lines (31 loc) · 946 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
31
32
33
34
35
36
37
38
39
40
import java.util.ArrayList;
public class Problem7 {
//By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
//What is the 10 001st prime number?
public Problem7() {
}
public static int calcPrime(int inp) {
ArrayList<Integer> primus = new ArrayList<Integer>();
primus.add(2);
primus.add(3);
int counter = 4;
while(primus.size() < inp) {
if(counter % 2 != 0 && counter%3 != 0) {
int countTemp = 4;
while(countTemp*countTemp <= counter) {
if(counter % countTemp == 0)
break;
countTemp ++;
}
if(countTemp*countTemp > counter) {
primus.add(counter);
}
}
counter++;
}
return primus.get(inp-1);
}
public static void main(String[] args) {
System.out.println(calcPrime(10001));
}
}