[ 문제 ]
주어진 수 N개 중에서 소수가 몇 개인지 찾아서 출력하는 프로그램을 작성하시오.
[ 입력 ]
- 첫 줄에 수의 개수 N이 주어진다.
- N은 100이하이다.
- 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.
[ 출력 ]
주어진 수들 중 소수의 개수를 출력한다.
[ 예제 입력 ]
4
1 3 5 7
[ 예제 출력 ]
3
import java.util.*;
import java.io.*;
public class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int count = 0;
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
int num = Integer.parseInt(st.nextToken());
int j = 1;
while (++j < num) {
if (num % j == 0)
break;
}
if (j == num)
count++;
}
System.out.println(count);
}
}
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
[Algorithm] 백준 1992 쿼드트리 (0) | 2021.08.19 |
---|---|
[Algorithm] 정올 1828 냉장고 (0) | 2021.08.17 |
[Algorithm] 백준 11653 소인수분해 (0) | 2021.08.16 |
[Algorithm] 백준 4153 직각삼각형 (0) | 2021.08.16 |
[Algorithm] 백준 11047 동전 0 (0) | 2021.08.15 |