So the task is to determine whether the sum C[n][1]+C[n][2]+...+C[n][k] is greater than X and do it FAST.

I can't do it fast.

#include <stdio.h>

typedef unsigned long long huge;

huge calc(int n, int k){

huge Up=k, Dn=0;

while(Up-Dn>1){

huge Md=(Up+Dn)/2;

huge cnt=0;

long double aux=1;

for(int i=1; cnt<k && i<=n; ++i){

aux*=(long double)Md+1-i;

aux/=i;

cnt+=aux;

}

if(cnt<k)

Dn=Md;

else

Up=Md;

}

return Dn+1;

}

int main(){

huge n,k, ans[1000];

int tot=0;

scanf("%llu %llu",&n,&k);

while(n>0 && k>0){

ans[tot++]=calc(n,k);

scanf("%llu %llu",&n,&k);

}

for(int i=0; i<tot; ++i)

printf("%llu\n",ans[i]);

return 0;

}