【BZOJ】【1008】【HNOI】越狱

快速幂


  大水题= =

  正着找越狱情况不好找,那就反过来找不越狱的情况呗……

  总方案是$m^n$种,不越狱的有$m*(m-1)^{n-1}$种= =

  负数搞搞就好了……

  莫名奇妙地T了好几发……

 1 /**************************************************************
 2     Problem: 1008
 3     User: Tunix
 4     Language: C++
 5     Result: Accepted
 6     Time:0 ms
 7     Memory:804 kb
 8 ****************************************************************/
 9  
10 //BZOJ 1008
11 #include<cstdio>
12 typedef long long LL;
13 const int P=100003;
14 LL Pow(LL a,LL b,LL P){
15     LL r=1;
16     for(;b;b>>=1,a=a*a%P) if (b&1) r=r*a%P;
17     return r;
18 }
19 int main(){
20     LL n,m;
21     scanf("%lld%lld",&m,&n);
22     LL ans=Pow(m,n,P)-Pow(m-1,n-1,P)*m%P;
23     if (ans<0) ans+=P;
24     printf("%lld\n",ans);
25     return 0;
26 }
View Code

 

posted @ 2015-04-09 11:43  Tunix  阅读(172)  评论(0编辑  收藏  举报