[洛谷P1313]计算系数

题目←

在wwq大佬博客发现的,将数论知识点总结的很好的题
也可以用杨辉三角求组合数,不过就跟着大佬练扩欧吧……

#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long
#define P 10007
using namespace std;
const int MAXN = 20000 + 50;
LL x,y;
void exgcd(LL a,LL b){
    if(!b){
        x = 1;
        y = 0;
        return;
    }
    exgcd(b,a%b);
    LL tmp = y;
    y = x - (a/b)*y;
    x = tmp;
}
LL a,b,k,n,m,ny,xs;
LL fast_pow(LL n,LL k){
    if(!k)return 1;
    LL tmp = fast_pow(n,k >> 1)%P;
    if(k & 1){
        return (tmp*tmp*(n%P))%P;
    }
    else return (tmp*tmp)%P;
}
int main(){
    cin >> a >> b >> k >> n >> m;
    LL tmp = 1;
    for(int i = 1;i <= m;i ++){
        tmp = (tmp*i)%P;
    }
    for(int i = 1;i <= k - m;i ++){
        tmp = (tmp*i)%P;
    }
    exgcd(tmp,P);
    x = (x%P + P)%P;
    tmp = 1;
    for(int i = 1;i <= k;i ++){
        tmp = (tmp*i)%P;
    }
    xs = (x*tmp)%P;
    xs = (((fast_pow(a,n)*fast_pow(b,m))%P)*xs)%P;
    cout << xs;
}

转载于:https://www.cnblogs.com/loi-pingxing/p/7778911.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值