求组合数模版

求组合数模版

#include<iostream>

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#define LL long long
using namespace std;
LL n,m;
LL Cnm(LL n,LL m)
{
    if(m>n/2)
        m=n-m;
    LL a=1,b=1;
    for(int i=1; i<=m; i++)
    {
        a*=n+1-i;
        b*=i;
        if(a%b==0)
        {
            a/=b;
            b=1;
        }
    }
    return a/b;
}
int main()
{
    while(scanf("%I64d %I64d",&n,&m)&&n)
    {
        printf("%I64d\n",Cnm(n,m));
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41370251/article/details/79165887
今日推荐