越狱

监狱有连续编号为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)

 

m^n-m*[(m-1)^(n-1)]

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<sstream>
typedef long long LL;
const LL mod = 100003;
LL powmod(LL a, LL n) 
{
    LL res = 1;
    while (n) 
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() 
{
    LL n, m;
    scanf("%lld%lld", &m, &n);
    LL ans = (powmod(m, n) - (m*powmod(m - 1, n - 1) % mod) + mod) % mod;
    printf("%lld\n", ans);
}

 

posted @ 2017-08-01 15:18  Edee  阅读(188)  评论(0编辑  收藏  举报