https://www.acmicpc.net/problem/1978
n까지 반복하며 소수를 판별한다.
소수란 1과 자기자신만을 포함하기 때문에 2부터 자기자신까지 반복한다.
자기자신까지 반복문 j 가 왔다는 건 같은 수가 없었다는 것이기에 소수이고 아닌 경우는 해당 반복을 멈춘다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int cnt = 0;
for(int i = 0; i < n; i++){
int m = sc.nextInt();
for(int j = 2; j <= m; j++){
if(m == j) cnt++;
if(m % j == 0) break;
}
}
System.out.println(cnt);
}
}```