Luogu3197 thought for a long time did not think, see the solution found himself good zz. It would be all right to subtract from the illegal situation. The whole situation is that everyone is randomly chosen, in total\ (m^n\)Situation, and then consider the illegal situation, that is, any adjacent two people can not believe in the same religion, the first person has a M religion can choose, behind everyone because can not be the same as the previous one, so everyone behind the m-1 a religion can choose. So the final answer is\ (m^n-m* (m-1) ^{n-1}\)Code
#include<cstdio>#include<iostream>using namespace std;typedef long long ll;const int mod=100003;ll read() { ll x=0, tmp=1; char ch=getchar(); //wxywwwwwwwwwwwwwwwwwwww while( (ch<'0') || (ch>'9') ){ if(ch=='-')tmp=-1; ch=getchar();} while( (ch>='0')&&(ch<='9') ){ x=x*10+ch-'0';ch=getchar(); }//wxywwwwwwwwwwwwwwww return (x*tmp);}ll qmi(ll x,ll y) { ll ans=1; ll now=x; while(y) { if(y&1) ans=ans*now%mod; now=now*now%mod; y>>=1; } return ans;}int main() { ll m=read(); ll n=read(); cout<<(qmi(m,n)%mod-qmi(m-1,n-1)*m%mod+mod)%mod; return 0;}
[luogu3197] Jailbreak