lucas定律 计算大数组合数取模

来源:互联网 发布:数据分析师培训机构 编辑:程序博客网 时间:2024/06/07 06:00


typedef long long ll;ll PowMod(ll a,ll b,ll MOD){ll ret=1;    while(b){if(b&1) ret=(ret*a)%MOD;        a=(a*a)%MOD;        b>>=1;}    return ret;}ll fac[100005];ll Get_Fact(ll p){fac[0]=1;for(int i=1;i<=p;i++)fac[i]=(fac[i-1]*i)%p;}ll Lucas(ll n,ll m,ll p){ll ret=1;while(n&&m){ll a=n%p,b=m%p;if(a<b) return 0;ret=(ret*fac[a]*PowMod(fac[b]*fac[a-b]%p,p-2,p))%p;n/=p;m/=p;}return ret;}


0 0
原创粉丝点击