注意
求组合数不能是res=i/j,如果这样写,根据优先级,会先算i/j,导致结果错误
应该先让resi, 再/j, 即res=res*i/j
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int n;
LL C(int a, int b){
LL res=1;
for(int i=a,j=1;j<=b;i--,j++){
res=res*i/j;
if(res>n) return res;
}
return res;
}
bool check(int k){
LL l=2*k, r=n;
while(l<r){
LL mid=(l+r)/2;
if(C(mid,k)>=n) r=mid;
else l=mid+1;
}
if(C(l,k)!=n) return false;
cout << l*(l+1)/2+k+1 << endl;
return true;
}
int main(){
cin >> n;
if(n==1){
cout << 1 << endl;
return 0;
}
for(int k=16;k>=0;k--){
if(check(k)) break;
}
return 0;
}