模板_计算组合数

//
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

LL C( LL n,LL m )
{
    if( n<m ) return 0;
    if( n==m || m==0 ) return 1;

    LL ans,i; n=n-m+1;
    for( ans=i=1;i<=m;i++ )
    {
        ans*=n++; ans/=i;       // 防溢出
    }
    return ans;
}

int main()
{
    LL n,m;
    while( cin>>n>>m )
    {
        cout<<C( n,m )<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/125223428
今日推荐