Question link: http://codeforces.com/contest/448/problem/D
Idea: use dichotomy
code:
#include<cstdio>#include<cmath>#include<iostream>using namespace std;__int64 n,m,k;__int64 f(__int64 x){ __int64 res=0; for(__int64 i=1;i<=n;i++) { __int64 minn=min(m,x/i); //计算第i行有多少个数比x小,并且最多也只要m个数比x小 res+=minn; //计算出比x小的数的共有多少个 } return res<k;}int main(){ while(scanf("%I64d%I64d%I64d",&n,&m,&k)==3) { __int64 l=1,r=n*m; while(l<r) { __int64 mid=(l+r)/2; if(f(mid))l=mid+1; else r=mid; } printf("%I64d\n",l); } return 0;}