1008: [HNOI2008]越狱

/**************************************************************
    Problem: 1008
    User: whymhe
    Language: C++
    Result: Accepted
    Time:80 ms
    Memory:1288 kb
****************************************************************/
 
//Pro: 1008: [HNOI2008]越狱
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
 
typedef long long LL;
 
const int mod=1e5+3;
 
LL m,n;
 
LL ksm(LL x,LL k)
{
    LL res=1;
    while(k)
    {
        if(k&1)
            res=res*x,res%=mod;
        x*=x,x%=mod;
        k>>=1;
    }
    return res;
}
 
int main()
{
    scanf("%lld%lld",&m,&n);
    printf("%lld",((ksm(m,n)-m%mod*ksm(m-1,n-1)%mod)+mod)%mod);
    return 0;
}
原文地址:https://www.cnblogs.com/lovewhy/p/9633703.html