Problem 568
Kth Smallest Number in a Multiplication Table
Hard · 30 pts · Math, Binary Search
Problem
An M × N multiplication table has the value i × j in row i and column j (both counted from 1). Find the K-th smallest number in the table, counting duplicates. The table can have 900 million cells, so it cannot be built. Binary search on the value x instead: row i contains min(floor(x / i), N) numbers that are at most x, so the count for x takes O(M) time.
Input
A single line with three integers M, N and K.
Output
Print the K-th smallest number in the table.
Constraints
1 <= M, N <= 30000; 1 <= K <= M × N
Example input
3 3 5
Example output
3
Explanation
The 3 × 3 table holds 1 2 3 / 2 4 6 / 3 6 9. Sorted, its values are 1 2 2 3 3 4 6 6 9, and the fifth one is 3. So for K = 5 the answer is 3.