BZOJ1008 [HNOI2008]越狱

只是一简单的减法。。ans = 总的方案数-不会发生越狱的方案数

一开始正着推,,,写了一灰常复杂的式子,都开始想怎么写矩阵快速幂了T^T

 

 1 #include <iostream>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod = 100003;
 5 LL pow(LL a,LL b){
 6     LL ret = 1;a%=mod;
 7     while(b){
 8         if(b%2)ret = (ret*a)%mod;
 9         if(b/=2)a=(a*a)%mod;
10     }
11     return ret;
12 }
13 int main(){
14     LL m,n;cin>>m>>n;
15     cout<<(mod+pow(m,n)-((m%mod)*pow(m-1,n-1))%mod)%mod<<endl;
16     return 0;
17 }

 

posted on 2015-08-03 19:50  round_0  阅读(127)  评论(0编辑  收藏  举报

导航