您的位置:首页 > 其它

[洛谷P1313]计算系数

2017-11-03 16:38 183 查看
题目←

在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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: