# BZOJ 1008([HNOI2008]越狱-等比数列求和)

## 1008: [HNOI2008]越狱

Time Limit: 1 Sec   Memory Limit: 162 MB
Submit: 2620   Solved: 1082
[ Submit][ Status][ Discuss]

2 3

6

## HINT

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

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define F (100003)
long long n,m;
long long sqr(long long a){return a*a;}
long long pow(long long a,long long b)
{
if (b==1) return a;
if (b==0) return 1;
long long p=sqr(pow(a,b/2))%F;
if (b%2) p=(p*a)%F;
return p;
}
int main()
{
//	freopen("bzoj1008.in","r",stdin);
scanf("%lld%lld",&m,&n);
cout<<(pow(m,n)%F-((m%F*pow(m-1,n-1))%F)+F)%F<<endl;
return 0;
}


posted @ 2013-06-12 17:06  jlins  阅读(92)  评论(0编辑  收藏