본문 바로가기
알고리즘 & 자료구조/백준

백준 1300

by 신재권 2022. 9. 22.
package baekjoon.이분탐색;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main1300 {

   static int N, K;

   public static void main(String[] args) throws Exception {
      input();
      go();
   }

   private static void go() {
      long L = 1, R = (long)N * N, ans = 0;
      while (L <= R) {
         long mid = (L + R) / 2;
         if (determination(mid)) {
            ans = mid;
            R = mid - 1;
         } else {
            L = mid + 1;
         }
      }
      System.out.println(ans);
   }

   private static boolean determination(long mid) {
      long cnt = 0;
      for (int i = 1; i <= N; i++) {
         cnt += Math.min(N, mid / i);
      }

      return cnt >= K;
   }

   private static void input() throws IOException {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      N = Integer.parseInt(br.readLine());
      K = Integer.parseInt(br.readLine());
   }
}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 2217  (0) 2023.07.11
백준 2003  (1) 2022.09.24
백준 17266  (0) 2022.09.22
백준 13702  (1) 2022.09.22
백준 2343  (0) 2022.09.21