Algorithm/백준 문제풀이
백준 1929 - 소수 구하기(자바 구현)
leedg36
2022. 2. 12. 19:16
반응형
public class Q_1929 {
public static void sieve(int min, int max) {
int[] prime = new int[max+1];
boolean[] check = new boolean[max+1];
for(int i=2; i<=max; i++) {
if(check[i] == false) {
if(i >= min) {
prime[i] = i;
System.out.println(i);
}
for (int j=i*2; j<=max; j+=i) {
check[j] = true; //값이 지워지는 경우를 true
}
}
}
}
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String readLine = bufferedReader.readLine();
String[] split = readLine.split(" ");
int min = Integer.parseInt(split[0]);
int max = Integer.parseInt(split[1]);
sieve(min, max);
}
}
반응형