Reprint please indicate the source: http://blog.csdn.net/u012860063? Viewmode = Contents
Link: http://codeforces.com/contest/448/problem/D
----------------------------------------------------------------------------------------------------------------------------------------------------------
Welcome to tianci Hut: http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
D. Multiplication tabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
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
The question is to select the K decimal number from an N * m multiplication table (do not ask me what the multiplication table is) (the same number is calculated multiple times ).
Example 2 3 4
The multiplication table is
1 2 3
2 3 4
The non-subtraction sequence is: 1, 2, 2, 3, 3, 4. The output value is 3 because the number is 3.
The Code is as follows:
# Include <iostream> # include <algorithm> using namespace STD; typedef long ll; ll n, m, K; ll min (ll a, LL B) {return a <B? A: B;} ll check (ll x) // find the number smaller than X {ll num = 0; For (INT I = 1; I <= N; I ++) {num + = min (M, X/I);} If (Num> = k) return 1; elsereturn 0;} int main () {While (CIN> N> m> K) {ll l = 0, r = N * m, ANS = 0; while (L <= r) {ll mid = (L + r)> 1; if (check (MID) {ans = mid; r = mid-1;} elsel = Mid + 1 ;} cout <ans <Endl;} return 0 ;}
Codeforces round #256 (Div. 2) D. Multiplication table (Binary Search)