File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # [ Bronze II] 소수 찾기 - 1978
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/1978 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 14264 KB, 시간: 104 ms
8+
9+ ### 분류
10+
11+ 소수 판정, 정수론, 수학
12+
13+ ### 제출 일자
14+
15+ 2025년 2월 13일 01:43:19
16+
17+ ### 문제 설명
18+
19+ <p >주어진 수 N개 중에서 소수가 몇 개인지 찾아서 출력하는 프로그램을 작성하시오.</p >
20+
21+ ### 입력
22+
23+ <p >첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.</p >
24+
25+ ### 출력
26+
27+ <p >주어진 수들 중 소수의 개수를 출력한다.</p >
28+
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+ import java .io .*;
3+
4+ public class Main {
5+ static int sum =0 ;
6+
7+ public static void main (String [] args ) throws IOException {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
9+ int N = Integer .parseInt (br .readLine ());
10+
11+ int [] nums = Arrays .stream (br .readLine ().split (" " )).mapToInt (x -> Integer .parseInt (x )).toArray ();
12+
13+ for (int i =0 ; i <N ; i ++){
14+ find (nums [i ]);
15+ }
16+ System .out .println (sum );
17+ }
18+
19+ public static void find (int num ){
20+ if (num ==1 ) return ;
21+
22+ // if(num==3){
23+ // sum++;
24+ // return;
25+ // }
26+
27+ for (int i =2 ; i <=num /2 ; i ++){
28+ if (num %i == 0 ){ // 약수가 있다면
29+ return ;
30+ }
31+ }
32+ // System.out.println("test");
33+ sum ++;
34+ return ;
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments