diff --git a/miniron-v/README.md b/miniron-v/README.md index d2bb009..fb6ad02 100644 --- a/miniron-v/README.md +++ b/miniron-v/README.md @@ -20,4 +20,5 @@ | 15차시 | 2024.02.15 | DP, 큰 수 연산 | [타일링](https://www.acmicpc.net/problem/1793) | [#56](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/56) | | 16차시 | 2024.02.18 | 수학 | [합](https://www.acmicpc.net/problem/1081) | [#61](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/61) | | 17차시 | 2024.02.21 | DP | [제곱수의 합](https://www.acmicpc.net/problem/1699) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/64) | +| 18차시 | 2024.02.24 | 이분 탐색 | [K번째 수](https://www.acmicpc.net/problem/1300) | [#66](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/66) | --- diff --git "a/miniron-v/\354\235\264\353\266\204 \355\203\220\354\203\211/1300-K\353\262\210\354\247\270 \354\210\230.cpp" "b/miniron-v/\354\235\264\353\266\204 \355\203\220\354\203\211/1300-K\353\262\210\354\247\270 \354\210\230.cpp" new file mode 100644 index 0000000..204d554 --- /dev/null +++ "b/miniron-v/\354\235\264\353\266\204 \355\203\220\354\203\211/1300-K\353\262\210\354\247\270 \354\210\230.cpp" @@ -0,0 +1,35 @@ +#include + +// [n][n] 배열에서 upper 이하 수의 개수를 센다. +long countNum(long n, long upper) { + long count = 0; + + for (long i = 1; i <= n && i <= upper; ++i) { + count += std::min(upper / i, n); + } + + return count; +} + +int main() { + long n, k; + std::cin >> n >> k; + + long low = 0, high = k; + long mid = 0; + + while (low + 1 < high) { + mid = (low + high) / 2; + long count = countNum(n, mid); + + if (count < k) { + low = mid; + } + + else if (count >= k) { + high = mid; + } + } + + std::cout << high; +} \ No newline at end of file