fork download
  1. #include <stdio.h>
  2. typedef unsigned long long huge;
  3. huge min(huge a, huge b) {
  4. return (a<b) ? a : b;
  5. }
  6. huge calc(huge n, huge k){
  7. huge Up=k, Dn=0;
  8. while(Up-Dn>1){
  9. huge Md=(Up+Dn)/2;
  10. huge cnt=0, aux=1;
  11. for(huge i=1; i<=min(n,Md); ++i){
  12. aux*=Md-i+1;
  13. aux/=i;
  14. cnt+=aux;
  15. if(cnt>=k)
  16. break;
  17. }
  18. if(cnt<k)
  19. Dn=Md;
  20. else
  21. Up=Md;
  22. }
  23. return Dn+1;
  24. }
  25. int main(){
  26. huge n,k, ans[1000];
  27. int tot=0;
  28. scanf("%llu %llu",&n,&k);
  29. while(n>0 && k>0){
  30. n=min(60LLU,n);
  31. ans[tot++]=calc(n,k);
  32. scanf("%llu %llu",&n,&k);
  33. }
  34. for(int i=0; i<tot; ++i)
  35. printf("%llu\n",ans[i]);
  36. return 0;
  37. }
Success #stdin #stdout 0s 15240KB
stdin
2 5
0 0
stdout
3