luogu1313计算系数题解--二项式定理

题目链接

https://www.luogu.org/problemnew/show/P1313

分析

二项式定理

\((a+b)^n=\sum_{k=0}^{n}{C^k_n a^k b^{n-k} }\)

于是我们要求的即是\(C^k_n \times a^n \times b^m\),于是直接快速幂,然后按公式\(C^k_n=\frac {n!}{(n-k)! \times k!}\),化成\(\prod_{i=k+1}^{i<=n} i \times ((n-k)!)^{-1}\)

代码

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <algorithm>
#include <cctype>
#define ll long long 
#define ri register int 
using std::min;
using std::max;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const ll p=10007;
int n,m,k,a,b;
inline ll ksm(ll a,ll c){
    ll ans=1;
    while(c){
        if(c&1)ans=ans*a%p;
        a=a*a%p;
        c=c>>1;
    }
    return ans;
}
ll fermat(ll a){
    return ksm(a,p-2);
}
int main(){
    /*ans=a^n*b^m*C(n,k)*/
    ll ans=1;
    read(a),read(b),read(k),read(n),read(m);
    ans=ksm(a,n)*ksm(b,m)%p;
    for(ri i=k;i>n;i--)ans=ans*i%p;
    ll tmp=1;
    for(ri i=k-n;i>=2;i--)tmp=tmp*i%p;
    ans=ans*fermat(tmp)%p;
    printf("%lld\n",ans);
    return 0;
}

转载于:https://www.cnblogs.com/Rye-Catcher/p/9648303.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值