Skip to content

Commit ced65e0

Browse files
authored
Merge pull request #926 from AlgorithmWithGod/lkhyun
[20250919] BOJ / G1 / K번째 수 / 이강현
2 parents 3a7c0df + 95b914c commit ced65e0

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static StringBuilder sb = new StringBuilder();
10+
static long N,K;
11+
12+
public static void main(String[] args) throws Exception {
13+
N = Integer.parseInt(br.readLine());
14+
K = Integer.parseInt(br.readLine());
15+
bw.write(binarySearch(1, N*N) +"");
16+
bw.close();
17+
}
18+
public static long binarySearch(long start, long end){
19+
long left = start;
20+
long right = end;
21+
long mid = 0;
22+
while (left <= right) {
23+
mid = (left + right) / 2;
24+
25+
long smaller = 0;
26+
long equal = 0;
27+
28+
for (int i = 1; i <= N; i++) {
29+
long maxJ = mid / i;
30+
31+
if (maxJ > N) maxJ = N;
32+
33+
if (mid % i == 0 && mid / i <= N) {
34+
smaller += maxJ - 1;
35+
equal++;
36+
} else {
37+
smaller += maxJ;
38+
}
39+
}
40+
41+
if (smaller >= K) {
42+
right = mid - 1;
43+
} else if (smaller + equal >= K) {
44+
return mid;
45+
} else {
46+
left = mid + 1;
47+
}
48+
}
49+
return mid;
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)