unsigned nChoosek( unsigned n, unsigned k )
{
if (k > n) return 0;
if (k * 2 > n) /*return*/ k = n-k; //remove the commented section
if (k == 0) return 1;
int result = n;
for( int i = 2; i <= k; ++i ) {
result *= (n-i+1);
result /= i;
}
return result;
}
#include <stdio.h>
int main(void)
{
printf("600 choose 3 is: %d\n", nChoosek
(600, 3)); return 0;
}
dW5zaWduZWQgbkNob29zZWsoIHVuc2lnbmVkIG4sIHVuc2lnbmVkIGsgKQp7CiAgICBpZiAoayA+IG4pIHJldHVybiAwOwogICAgaWYgKGsgKiAyID4gbikgLypyZXR1cm4qLyBrID0gbi1rOyAgLy9yZW1vdmUgdGhlIGNvbW1lbnRlZCBzZWN0aW9uCiAgICBpZiAoayA9PSAwKSByZXR1cm4gMTsKCiAgICBpbnQgcmVzdWx0ID0gbjsKICAgIGZvciggaW50IGkgPSAyOyBpIDw9IGs7ICsraSApIHsKICAgICAgICByZXN1bHQgKj0gKG4taSsxKTsKICAgICAgICByZXN1bHQgLz0gaTsKICAgIH0KICAgIHJldHVybiByZXN1bHQ7Cn0KCiNpbmNsdWRlIDxzdGRpby5oPgoKaW50IG1haW4odm9pZCkKewogICAgcHJpbnRmKCI2MDAgY2hvb3NlIDMgaXM6ICVkXG4iLCBuQ2hvb3Nlayg2MDAsIDMpKTsKICAgIHJldHVybiAwOwp9