http://ac.jobdu.com/problem.php?pid=1040
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
|
import
java.util.Scanner;
publicclass
Main {
publicstatic
void
main(String[] args) {
Scanner sc =
new
Scanner(System.in);
while
(sc.hasNext()) {
int
n = sc.nextInt();
System.out.println(getPrimeNumber(n));
}
}
publicstatic
int
getPrimeNumber(
int
n) {
int
[] total =
newint
[
10000
];
total[
0
] =
2
;
int
count =
1
;
for
(
int
i =
3
; i <=
200000
; i++) {
boolean
flag =
true
;
int
temp = i;
for
(
int
j =
2
; j <= Math.sqrt(temp); j++) {
if
(temp % j ==
0
) {
flag =
false
;
break
;
}
}
if
(flag) {
if
(count<
10000
)
total[count++] = i;
}
}
if
(n > total.length)
return
-
1
;
return
total[n -
1
];
}
}
|