bzoj 1008 //1008: [HNOI2008]越狱 //在线测评地址https://www.lydsy.com/JudgeOnline/problem.php?id=1008
更多题解,详见https://blog.csdn.net/mrcrack/article/details/90228694BZOJ刷题记录
//1008: [HNOI2008]越狱
//在线测评地址https://www.lydsy.com/JudgeOnline/problem.php?id=1008
//容斥原理+快速幂
//所有状态m^n
//不越狱状态m*(m-1)^(n-1)
//越狱状态m^n-m*(m-1)^(n-1)
//样例计算2^3-2*(2-1)^(3-1)=6
//模100003来看int溢出,需采用long long
//该题有个别扭的地方,数据输入,先输入 M种宗教,再输入 N个房间,与问题表述正好相反
//样例通过,提交AC.2019-7-25 20:47
#include
#define LL long long
#define mod 100003
LL m,n;
LL quick_pow(LL a,LL b){//a^b
LL ans=1;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod,b>>=1;//此处写成b>>=1;
}
return ans;
}
int main(){
LL ans;
scanf("%lld%lld",&m,&n);
ans=(quick_pow(m,n)-m*quick_pow(m-1,n-1)%mod+mod)%mod;//m^n-m*(m-1)^(n-1)
printf("%lld\n",ans);
return 0;
}