这道二分fix了半年 我还是那么🥬.....
注意边界
先找规律,再二分 还学到了暴力算C(i,j)的超级暴力手段...
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define int long long
const int N = 1e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
int gcd(int a,int b){return b?a:gcd(b,a%b);}
int lcm(int a,int b){return a*b/gcd(a,b);}
int qmi(int a,int b,int mod){int res=1;while(b){if(b&1)res=res*a%mod;b>>=1;a=a*a%mod;}return res;}int n,q,m;// int e[N],ne[N],w[N],h[N],idx;
// void add(int a,int b,int c){// e[idx] = b,ne[idx] = h[a],w[idx] = c,h[a] = idx++;
// }int cal(int a,int b){int res = 1;for(int i=a,j=1;j<=b;++j,--i){res = res*i/j;if(res>n)return res;}return res;
}void solve()
{cin>>n;if(n==1){cout<<1;return;}for(int i=17;i>=0;--i){int l = i*2,r = inf;while(l+1!=r){int mid = (l+r)/2;if(cal(mid,i)>n)r = mid;else l = mid;}if(cal(l,i)==n){cout<<(1+l)*l/2+i+1<<"\n";break;}}}signed main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;//cin>>_;_ = 1;while(_--)solve();return 0;
}