Skip to content

Commit

Permalink
Merge pull request #44 from AlgoLeadMe/13-mong3125
Browse files Browse the repository at this point in the history
13 mong3125
  • Loading branch information
mong3125 authored May 2, 2024
2 parents b75b28a + 3db1113 commit 3c921b6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions mong3125/이진탐색/BOJ1300_K번째수.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package 이진탐색;

import java.util.Scanner;

public class BOJ1300_K번째수 {
static int n;
static int k;
static int answer;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
k = sc.nextInt();

index(0, k);
System.out.println(answer);
}

public static void index(int front, int back) {
if (front > back) return;

int mid = (front + back) / 2;
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += Math.min(mid / i, n);
}

if (sum < k) {
index(mid + 1, back);
} else {
answer = mid;
index(front, mid - 1);
}
}
}

0 comments on commit 3c921b6

Please sign in to comment.