https://blog.csdn.net/njuptACMcxk/article/details/116426985?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.nonecase

记录蓝桥杯的第一道题

收藏学习

#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 1e5 + 7;
typedef long long ll;
ll n,sum;
ll C(int a,int b){//C5 2
	ll res=1;
	for(ll up = a, down = 1; down <= b; up --, down ++)
    {
        res = res * up / down;
        if(res > n) return res;  //ÕÒµ½µÄÊǵÚÒ»¸ö³öÏÖnµÄλÖà  a¾¡Á¿Ð¡Ò»µã     
    }
	return res;
}
//ll C(int a, int b)
//{
//    ll res = 1;
//    for(ll up = a, down = 1; down <= b; up --, down ++)
//    {
//        res = res * up / down;
//        if(res > n) return res;
//    }
//    return res;
//}
bool check(int j){
	ll l = 2*j,r=max(n,l);
	while(l<r){
		ll k = (l+r)/2;
		if(C(k,j)>=n) r=k;
		else l = k+1;
	}
	if(C(r,j)!=n)return false;
	cout << (r+1)*r/2+j+1<<endl;
	return true;
}
int main(){
	cin >> n;
	for(int j =16;;j--){
		if(check(j)) break;
	}
    return 0;
}