BZOJ 1008

来源:互联网 发布:win10改mac主题 编辑:程序博客网 时间:2024/05/23 01:02

Description

监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱

Input

输入两个整数M,N.1<=M<=10^8,1<=N<=10^12

Output

可能越狱的状态数,模100003取余

Sample Input

2 3

Sample Output

6

HINT

6种状态为(000)(001)(011)(100)(110)(111)



/*************************************************************************> File Name: problem.cpp> Author: wjzdmr> Mail: wjzdmr@gmail.com> Created Time: 2014年09月14日 星期日 21时46分55秒 ************************************************************************/#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <cctype>#include <map>#include <set>#include <bitset>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iomanip>#include <cstdlib>#include <ctime>#include <cassert>#include <limits>#include <fstream>using namespace std;#define mem(A, X) memset(A, X, sizeof A)#define pb(x) push_back(x)#define mp(x,y) make_pair((x),(y))#define vi vector<int>#define all(x) x.begin(), x.end()#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)#define sz(x) (int)((x).size())#define sl(a) strlen(a)#define rep(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))#define Rep(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define min3(a,b,c) min(a,min(b,c))#define max3(a,b,c) max(a,max(b,c))#define dbg(a) cout << a << endl;#define fi first#define se secondtypedef long long int64;int gcd(const int64 &a, const int64 &b) { return b == 0 ? a : gcd(b, a % b); }int64 int64pow(int64 a, int64 b){ if (b == 0) return 1; int64 t = int64pow(a, b / 2); if (b % 2) return t * t * a; return t * t; }const int inf = 1 << 30;const double eps = 1e-8;const double pi = acos(-1.0);const int MAX_N = 10005;const int mod = 100003;int64 n, m;int64 pow_mod(int64 a, int64 b, int64 n){    if (b == 0) {        return 1 % n;    }    int64 tmp = pow_mod(a, b >> 1, n);    tmp = tmp * tmp % n;    if (b & 1)         tmp = tmp * a % n;    return tmp;}void work(){    //总共的宗教信仰情况:m×m×m... m^n    int64 tot = pow_mod(m, n, mod);    //不会越狱的宗教信仰情况:m×(m-1)×(m-1)... m×(m-1)^(n-1)    int64 res = pow_mod(m - 1, n - 1, mod);    res = res * (m % mod) % mod;    //越狱的宗教信仰情况:tot - res    int64 ans = tot - res;    if (ans < 0)        ans = (ans + mod) % mod;    cout << ans << endl;}int main(){    while (cin >> m >> n) {        work();    }    return 0;}

0 0
原创粉丝点击