-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |