当前位置:网站首页>Template_ Calculate number of combinations

Template_ Calculate number of combinations

2022-06-10 22:44:00 This question AC sleep again

//
#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;       //  Anti overflow 
    }
    return ans;
}

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

原网站

版权声明
本文为[This question AC sleep again]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101642254935.html