bzoj1008 [HNOI2008]越狱(排列组合+逆元)

#include<bits/stdc++.h>
using namespace std;
const int mod=100003;
typedef long long ll;
ll power (ll a,ll b) {
    if (b==0) return 1;
    ll cnt=power(a,b/2);
    cnt=cnt*cnt%mod;
    if (b%2==1) cnt=cnt*a%mod;
    return cnt;
}

ll N,M;
int main () {
    scanf("%lld%lld",&M,&N);
    ll ans=power(M,N);
    ans=(ans-M*power(M-1,N-1)%mod)%mod;
    while (ans<mod) ans+=mod;
    printf("%lld\n",ans%mod);
    return 0;
}

 

posted @ 2020-03-14 21:19  zlc0405  阅读(122)  评论(0编辑  收藏  举报