监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱
1<=M<=10^8,1<=N<=10^12
水题
一共有m ^ n种状态,若没有发生越狱的情况,第一个人有m种选择,第二个人有m - 1种选择,后面每个人都有m - 1种选择,所以ans = m ^ n - m * (m - 1) ^ (n - 1)
//最后那里如果ans小于0要特判,不然会wa
#include<map>
#include<cmath>
#include<cstdio>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
inline int read() {
int x = 0, flag = 1; char ch = getchar();
while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * flag;
}
#define rep(ii, aa, bb) for (int ii = aa; ii <= bb; ii++)
#define drp(ii, aa, bb) for (int ii = aa; ii >= bb; ii--)
#define ll long long
#define mod 100003
ll mult(ll a, ll b) {
ll c = 1, d = a % mod;
while (b > 0) {
if (b & 1) c = (c % mod * d % mod) % mod;
b >>= 1;
d = (d % mod * d % mod) % mod;
}
return c;
}
int main() {
ll m, n;
cin >> m >> n;
int ans = (mult(m, n) - m * mult(m - 1, n - 1) % mod) % mod;
if (ans < 0) ans += mod;
cout << ans;
return 0;
}