상세 컨텐츠

본문 제목

백준 1978번

백준 알고리즘 풀이

by 발발개발 2020. 12. 23. 12:39

본문

원본 : www.acmicpc.net/problem/1978

 

1978번: 소수 찾기

첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.

www.acmicpc.net

 

풀이

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

		int n = Integer.parseInt(reader.readLine());
		int num[] = new int[n];
		
		String str = reader.readLine();
		for (int i = 0; i < num.length; i++) {
			num[i] = Integer.parseInt(str.split(" ")[i]);
		}
		
		int count = 0;
		for (int i = 0; i < num.length; i++) {
			int aliquotCount = 0;
			for (int j = 1; j <= num[i]; j++) {
				if (num[i] % j == 0) {
					aliquotCount++;
				}
			}
			if (aliquotCount == 2) {
				count++;
			}
		}
		
		writer.write(String.valueOf(count));

		writer.flush();
	}
	
}

'백준 알고리즘 풀이' 카테고리의 다른 글

백준 1929번  (0) 2020.12.23
백준 2581번  (0) 2020.12.23
백준 1011번  (0) 2020.12.23
백준 2775번  (0) 2020.12.16
백준 10250번  (0) 2020.12.16

관련글 더보기

댓글 영역