Codeforces Round #256 (Div. 2) D. Multiplication Table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.