原题链接https://www.luogu.com.cn/problem/P8749
有组合数的性质
#include <iostream>
#include <map>
#include <cmath>
#define ll long long
ll n;
const ll inf = 1e9;
ll C(ll a,ll b){
ll res = 1;
for(ll i = a,j = 1; j <= b; i --,j ++){
res = res * i / j;
if(res > n) return res;
}
return res;
}
void solve(){
std::cin >> n;
if(n == 1){
std::cout << 1;
return ;
}
for(ll i = 16; i >= 0; i --){
ll l = 2 * i;
ll r = inf;
while(l <= r){
ll mid = (l + r) >> 1;
ll ans = C(mid,i);
if(ans == n){
std::cout << (mid * (mid + 1)) / 2 + i + 1 << "\n";
return;
}
else if(ans < n){
l = mid + 1;
}
else r = mid - 1;
}
}
return ;
}
int main(){
ll t = 1;
while(t --)
solve();
return 0;
}