卢梭曾经说过:“人生而自由,又不往在枷锁中。” 但我仍要说:不自由,毋宁死。
二分查找
https://leetcode.cn/problems/kth-smallest-number-in-multiplication-table/
class Solution {
public int findKthNumber(int m, int n, int k) {
int left = 1, right = m * n;
while (left < right) {
int x = left + (right - left) / 2;
int count = x / n * n;
for (int i = x / n + 1; i <= m; ++i) {
count += x / i;
}
if (count >= k) {
right = x;
} else {
left = x + 1;
}
}
return left;
}
}