Skip to content

Instantly share code, notes, and snippets.

@BrendenHJH
Created May 9, 2018 07:13
Show Gist options
  • Save BrendenHJH/f939d1485c7a5f2480dad678ce7c5e59 to your computer and use it in GitHub Desktop.
Save BrendenHJH/f939d1485c7a5f2480dad678ce7c5e59 to your computer and use it in GitHub Desktop.
백준 2960 에라토스네스의 체
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
boolean[] isPrime = new boolean[n+1];
for(int i = 2; i <= n; i++) {
isPrime[i] = true;
}
int cnt = 0;
for(int i = 2; i <= n; i++) {
for(int j = i; j <= n; j += i) {
if(!isPrime[j]) continue;
isPrime[j] = false;
++cnt;
if(cnt == k) {
System.out.println(j);
System.exit(0);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment