# 【BZOJ 1008】[HNOI2008]越狱

【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1008

【题意】

【题解】

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

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
const LL mod = 100003;

LL m,n,temp;

void ksm(LL x,LL y)
{
if (y==0) return;
ksm(x,y>>1);
temp = (temp*temp)%mod;
if (y&1)
temp = (temp*x)%mod;
}

int main()
{
//freopen("F:\\rush.txt","r",stdin);
//m^n-m*(m-1)^(n-1)
rel(m),rel(n);
temp = 1;
ksm(m,n);
LL ans = temp;
temp = 1;
ksm(m-1,n-1);
temp = (m*temp)%mod;
ans = (ans-temp+mod)%mod;
cout << ans << endl;
return 0;
}

posted @ 2017-10-04 18:45  AWCXV  阅读(53)  评论(0编辑  收藏