[洛谷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;
}
posted @ 2017-11-03 16:40  _平行  阅读(118)  评论(0编辑  收藏  举报