컴공 공부/백준

[백준 알고리즘] 1978번 소수찾기 자바

무무뭉? 2021. 1. 7. 17:14
import java.io.IOException;
import java.util.Scanner;

public class Main {
public static void main(String args[]) throws IOException {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sosuCnt = 0, cnt = 0;

    for (int i = 1; i <= num; i++) {
        int num2 = sc.nextInt();
        sosuCnt = 0;

        for (int j = 1; j <= num2; j++) {
            if (num2 % j == 0)
                sosuCnt++;
        }

        if (sosuCnt == 2)
            cnt++;
    }
    System.out.print(cnt);
}
}