Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18-miniron-v #66

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions miniron-v/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
35 changes: 35 additions & 0 deletions miniron-v/이뢄 탐색/1300-K번째 수.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>

// [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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n*n λ°°μ—΄ 없이 μ–΄λ–»κ²Œ 값을 찾지? λΌλŠ” 생각을 ν–ˆμ—ˆλŠ”λ° μ‹ κΈ°ν•˜λ„€μš”..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 λ¬Έμ œλŠ” NxN 배열을 λ§Œλ“€κ³ , 1차원 λ°°μ—΄λ‘œ λ°”κΎΌ λ’€ μ˜€λ¦„μ°¨μˆœ μ •λ ¬κΉŒμ§€ ν•˜κΈ° λ•Œλ¬Έμ— 2차원 배열을 μ“°λŠ” 게 더 ν—€λ©œ 것 κ°™μ•„μš”.

}

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;
}