-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1929.java
32 lines (30 loc) · 939 Bytes
/
1929.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
백준 1929번 - 소수 구하기
https://www.acmicpc.net/problem/1929
알고리즘 분류
1. 수학
2. 정수론
3. 소수 판정
4. 에라토스테네스의 체
*/
import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int m = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());
boolean pN[] = new boolean[n+1];
pN[1] = true;
for(int i=2; i*i<=n; i++)
if(!pN[i])
for(int j=i*i; j<=n; j+=i)
pN[j] = true;
StringBuilder sb = new StringBuilder();
for(int i=m; i<=n; i++)
if(!pN[i])
sb.append(i+"\n");
System.out.println(sb);
}
}