알고리즘 및 자료구조/문제
백준알고리즘 1929번 소수 구하기
ktko
2018. 5. 14. 09:03
백준알고리즘
https://www.acmicpc.net/problem/1929
import java.util.Scanner; public class Main2 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = scan.nextInt(); int b = Integer.parseInt(scan.nextLine().trim()); boolean[] check = new boolean[b+1]; for(int i=0; i < check.length; i++) check[i] = true; int sqrt = (int) Math.sqrt(b); for(int i=2; i <= sqrt; i++) { if(check[i] == true) { for(int j=i; j * i <= b; j++) { check[i*j] = false; } } } for(int i=a; i <=b; i++) { if(i == 1) continue; if(check[i]) System.out.println(i); } } }