题目描述
题解
总共有可能的方案数:
ans1=mn
相邻的两位两两不相同的方案数:
ans2=m∗(m−1)n−1
(第一个房间有m种选择,其余都有m-1种选择)
答案即为ans1-ans2
代码
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define LL long long
const int Mod=100003;
LL n,m,ans1,ans2,ans;
inline LL fast_pow(LL a,LL p)
{
LL ans=1; a%=Mod;
for (;p;p>>=1,a=a*a%Mod)
if (p&1)
ans=ans*a%Mod;
return ans;
}
int main()
{
scanf("%lld%lld",&m,&n);
ans1=fast_pow(m,n);
ans2=fast_pow(m-1,n-1)*m%Mod;
ans=((ans1-ans2)%Mod+Mod)%Mod;
printf("%lld\n",ans);
}
总结
减完了之后mod要考虑到减成负数的情况,最好写%Mod)+Mod)%Mod