Bizon the Champion isn ' t just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n? x? m Multiplication table, where the element on the intersection of theI-th Row andJ-th column equals I· J (The rows and columns of the table is numbered starting from 1). Then he's asked:what number in the table is thek-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write off all n• M numbers from the table in the non-decreasing order and then the K-th number you write out is called the k-th largest number.
Input
The single line contains integers n, m and K (1?≤? N,? M.≤?5 105; 1?≤? k? ≤? N· m).
Output
Print the k-th largest number in a n? x? M multiplication table.
Sample Test (s) input
2 2 2
Output
2
Input
2 3 4
Output
3
Input
1 10 5
Output
5
Note
A 2?x?3 multiplication table looks like this:
1 2 32) 4 6
Test Instructions: let you find the number of K-large in a n*m multiplication matrix.
Idea: Two-point search, count the results of each row
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < Cmath>typedef Long Long ll;using namespace Std;ll N, m, k;int check (ll x) {ll res = 0;for (int i = 1; I <= n; i++) { ll tmp = min (i*m, x); res + = tmp/i;} return res < K;} LL search (ll L, ll R) {while (L < R) {ll mid = (L + R)/2;if (check (mid)) L = mid + 1;else r = Mid;} return r;} int main () {cin >> n >> m >> K;ll right = n * m, left = 1;ll ans = search (left, right); cout << ans << Endl;return 0;}
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Codeforces Round #256 (Div. 2) D. Multiplication Table