본문 바로가기
Algorithm/Baekjoon Online Judge

[Java] [Math] 백준 1978 소수 찾기 브론즈2

by 제우제우 2024. 5. 4.

https://www.acmicpc.net/problem/1978

import java.io.*;
import java.util.*;
public class Main {
    static int answer;
    
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());

        while (n-->0){
            isPrime(Integer.parseInt(st.nextToken()));
        }

        System.out.println(answer);

    }
    public static void isPrime(int n){
        if(n == 1) return;
        for(int i = 2; i * i <= n; i++){
            if(n % i == 0) return;
        }
        answer++;
    }

}