Bj2960
title: 2025-08-13 author: 강병호 date: 2025-08-13 category: TIL/강병호/2025/08 layout: post (자유) —
class Main {
static int N;
static int result = 0;
static boolean[] arr = new boolean[1001];
static int cnt = 0;
// static List arr = new ArrayList<>(); // 이미 배수처리 되었는지 확인용
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int primeNum = 2;
for (int i = 2; i <= N; i++) {
// 1. 지우기 처리
if (arr[i]) { // 소수 아님.
continue;
}
// i * j : 배수
int j = 1;
int num = i * j;
do {
num = i * j;
if (arr[num]) {
j++;
} else {
arr[num] = true;
cnt += 1;
if (cnt == K) {
result = num;
break;
}
}
} while (i * j <= N);
if (result != 0) {
break;
}
}
System.out.println(result);
}
}