-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1978.java
More file actions
31 lines (23 loc) Β· 757 Bytes
/
1978.java
File metadata and controls
31 lines (23 loc) Β· 757 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
import java.io.*;
import java.util.*;
import static java.lang.Math.sqrt;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
int count = 0;
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
while (st.hasMoreTokens()) {
int num = Integer.parseInt(st.nextToken());
if (isPrime(num)) count++;
}
System.out.println(count);
}
public static boolean isPrime(int num) {
if (num == 1) return false;
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0) return false;
}
return true;
}
}