baekjoon 4948

0_23·2022년 11월 28일
0

[BOJ][Java]

목록 보기
34/55
post-thumbnail

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int N = Integer.parseInt(br.readLine());
        while(N!=0) {
            int cnt = 0;
            for (int i = N+1; i <= 2*N; i++) {
                boolean isPrime = true;
                if (i == 1) isPrime = false;
                for (int j = 2; j * j <= i && isPrime; j++) {
                    if (i % j == 0) {
                        isPrime = false;
                    }
                }
                if (isPrime) {
                    cnt++;
                }
            }
            bw.write(cnt + "\n");
            N = Integer.parseInt(br.readLine());
        }
        bw.flush();
        br.close();
        bw.close();
    }
}

0개의 댓글