[洛谷P1313]計算係數
阿新 • • 發佈:2019-01-26
在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;
}