排列组合+逆元模板

时间:2020-07-30 18:02:31   收藏:0   阅读:69

 

运用费马小定理

#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
int v[maxn];
ll ppow(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}
ll solve(ll now,ll num)
{
    ll ans=1;
    for(ll i=now;i>now-num;--i)
        ans=(ans*i)%mod;
    for(ll i=1;i<=num;++i)
    {
        ans=(ans*ppow(i,mod-2))%mod;
    }
    return ans;
}
int main()
{
    printf("%d\n",solve(9,3));
        return 0;
}    

 

原文:https://www.cnblogs.com/kongbursi-2292702937/p/13404487.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!