码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ1008 [HNOI2008]越狱

时间:2015-08-03 20:39:20      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

只是一简单的减法。。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 }

 

BZOJ1008 [HNOI2008]越狱

标签:

原文地址:http://www.cnblogs.com/GJKACAC/p/4700226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!