[ 문제 ]
세준이는 크기가 인 배열 를 만들었다. 배열에 들어있는 수 이다. 이 수를 일차원 배열 에 넣으면 의 크기는 이 된다. 를 오름차순 정렬했을 때, 를 구해보자.
배열 와 의 인덱스는 1부터 시작한다.
package binary_search;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class bj1300 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static int N, k;
static long[][] A;
static long[] B;
public static void main(String[] args) throws IOException {
N = Integer.parseInt(br.readLine());
k = Integer.parseInt(br.readLine());
long answer = 0;
long low = 1;
long hi = N * N;
while(low < hi){
long mid = (low + hi) / 2;
if(counting(mid) < k){
low = mid + 1;
}
else {
hi = mid;
}
}
System.out.println(low);
}
private static long counting(long n){
long res = 0;
for(int i = 1 ; i <= N ; i ++){
res += Math.min(n/i, N);
}
return res;
}
}