There are few ideas to explain in seconds. It can be described that there are m dyeing schemes for the lattice with a length of N in pairs. If there are two adjacent grids with the same color, it is difficult to solve the problem, consider that any two adjacent grids on the back of the problem have different colors. The first lattice can be painted with any color M, n-1-1 grids cannot be the same as the previous one. The total number of grids is m ^ N. Therefore, the answer is m ^ N-M (m-1) ^ n-1 because of the high modulo and power of answers, you can consider the tip horse theorem or quick power optimization.
Because the data is too 2, the int reading at the beginning successfully contributed 3 wa Tat
# Include <iostream>
# Include <cstdio>
# Include <math. h>
Using namespace STD;
Long long KSM (long K, long)
{
If (k = 0) return 1;
If (k = 1) return;
If (K % 2 = 0) return KSM (K/2, a) * KSM (K/2, a) % 100003;
Else return (KSM (K-1, A) * A) % 100003;
}
Int main ()
{
Long long m = 0, n = 0, ans;
Scanf ("% LLD", & M, & N );
Ans = (KSM (n, m)-(M * KSM (N-1 m-1) % 100003 + 100003) % 100003;
Printf ("% LLD", ANS );
Return 0;
}
Bzoj 1008: [hnoi2008] jailbreak [combination]