-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1978.java
More file actions
48 lines (42 loc) ยท 1.06 KB
/
_1978.java
File metadata and controls
48 lines (42 loc) ยท 1.06 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
package backjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
// https://www.acmicpc.net/problem/1978
// ์์ ์ฐพ๊ธฐ
// ์์๋ 1๊ณผ ์๊ธฐ ์์ ์ผ๋ก๋ง ๋๋ ๋จ์ด์ง๋ 1๋ณด๋ค ํฐ ์์ ์ ์
public class _1978 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//sol memory 11560 runtim 76
br.readLine(); // N์ ์ฐ์ง์๊ณ ๋ฒ๋ฆผ
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int cnt = 0;
while(st.hasMoreTokens()){
// ์์์ธ๊ฒฝ์ฐ true, ์๋๊ฒฝ์ฐ false
boolean isPrime = true;
int num = Integer.parseInt(st.nextToken());
if(num == 1) {
continue;
}
for(int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
if(isPrime) {
cnt++;
}
}
System.out.println(cnt);
}
}
/*
input
4
1 3 5 7
output
3
*/