baekjoon 1929

0_23·2022년 11월 28일
0

[BOJ][Java]

목록 보기
33/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));
        StringTokenizer token = new StringTokenizer(br.readLine());
        int M = Integer.parseInt(token.nextToken()),N = Integer.parseInt(token.nextToken());
        for (int i = M; i <= 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) bw.write(i + "\n");
        }
        bw.flush();
        br.close();
        bw.close();
    }
}

0개의 댓글