


count를 했으며 이 count가 K와 같을때 그때의 약수를 출력했으며 for문을 다 돌았는데도 count가 K와 같지 않고 작다면 0을 출력하도록 했다. 생각보다 간단했던 로직 완성!import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = bfr.readLine();
StringTokenizer st = new StringTokenizer(str, " ");
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int divisor;
int count = 0;
for (int j = 1; j <= N; j++) {
if (N % j == 0) {
divisor = j;
++count;
if (count == K) {
bfw.write(String.valueOf(divisor));
break;
}
}
}
if (count < K) {
bfw.write("0");
}
bfr.close();
bfw.flush();
bfw.close();
}
}