Artifact d63ada0513560bce41ea7d1a204630cbf157065b
- File
_lib/typical/comb.cpp
- 2011-02-23 09:21:16 - part of checkin [4fd800b3a8] on branch trunk - Copied from private svn repository. (user: kinaba) [annotate]
- File
lib/typical/comb.cpp
- 2011-02-23 11:18:09 - part of checkin [23dfcca431] on branch trunk - renamed _lib to lib (user: kinaba) [annotate]
//-------------------------------------------------------------
// number of combinations choosing k out of n
// # you might better consider to use Pascal's triangle
// # for comb modulo some number...
//
// Verified by
// - SRM 350 Div1 LV2
//-------------------------------------------------------------
LL comb(LL n, LL k)
{
k = min(k, n-k);
LL c = 1;
for(LL i=0; i<k; ++i)
c *= n-i, c /= i+1;
return c;
}