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 paintedN? ×?MMultiplication table, where the element on the intersection ofI-Th row andJ-Th Column equalsI·J(The rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table isK-Th largest number? Bizon the champion always answered correctly and immediately. Can you repeat his success?

Consider the given multiplication table. If you write out allN·MNumbers from the table in the non-decreasing order, thenK-Th number you write out is calledK-Th largest number.

Input

The single line contains IntegersN,MAndK(1? ≤?N,?M? ≤? 5 · 105; 1? ≤?K? ≤?N·M).

Output

PrintK-Th largest number inN? ×?MMultiplication 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? ×? 3 multiplication table looks like this:

1 2 32 4 6
Let's find the k-th largest number in a multiplication matrix of N * m.

Idea: Perform binary search to 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;}


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.