LUOGU P1313 计算系数 (组合数学)

本文介绍了一种使用二项式定理解决数学问题的方法,并通过一个具体的编程实例展示了如何在C++中实现快速幂运算和组合数计算,以求解与两个数的幂次相关的组合问题。

解题思路

比较简单的题,用二项式定理即可。

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>

using namespace std;
const int MAXN = 1005;
const int mod = 10007;
typedef long long LL;

inline int rd(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)) {f=ch=='-'?0:1;ch=getchar();}
    while(isdigit(ch))  {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return f?x:-x;
}

int a,b,k,n,m;
LL C[MAXN][MAXN];

int fast_pow(int x,int y){
    int ret=1;
    for(;y;y>>=1){
        if(y&1) ret=(LL)ret*x%mod;
        x=(LL)x*x%mod;
    }
    return ret;
}

int main(){
    a=rd(),b=rd(),k=rd(),n=rd(),m=rd();
    for(int i=1;i<=k+1;i++){
        C[i][0]=1;
        for(int j=1;j<=i;j++) C[i][j]=C[i-1][j]+C[i-1][j-1],C[i][j]%=mod;
    }
    printf("%lld",(LL)fast_pow(a,n)*fast_pow(b,m)%mod*C[k+1][n]%mod);
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/sdfzsyq/p/9763190.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值