-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1300.java
More file actions
44 lines (39 loc) · 1.33 KB
/
Copy path1300.java
File metadata and controls
44 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// https://www.acmicpc.net/problem/1300
// K번째 수
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
private static int n, k;
private static final int MAX = 1000000000;
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(reader.readLine());
k = Integer.parseInt(reader.readLine());
int start = 1, end = k;
int mid = -1, index, answer = k;
while(start+1 < end){
mid = start + (end - start)/2;
index = getMaxIndexOf(mid);
if(index < k){ // cant be answer, setup start
start = mid;
}
else if(index >= k){ // can be answer, but should search min
answer = Math.min(answer, mid);
if(end == mid) break;
end = mid;
}
}
if(getMaxIndexOf(start) >= k)
answer = Math.min(answer, start);
if(getMaxIndexOf(end) >= k)
answer = Math.min(answer, end);
System.out.println(answer);
}
private static int getMaxIndexOf(int value){
int result = 0;
for(int i=Math.min(n, value); i>=1; i--)
result += Math.min(n, value/i);
return result;
}
}