组合数公式
代码
#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long LL;
using namespace std;
LL calc(LL n, LL m) //C(n, m):从n个数中选出m个数字 n!/(m! * (n - m)!)
{
LL a = 1, b = 1;
for (int i = n; i >= n - m + 1; i--) a *= i;
for (int i = 1; i <= m; i++) b = b * i;
return a / b;
}
int main()
{
cout << calc(4, 2); //6
return 0;
}