【bzoj 1008】[HNOI2008]越狱
2017-03-27 19:37
274 查看
[HNOI2008]越狱
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 8811 Solved: 3812
[Submit][Status][Discuss]
Description
监狱有连续编号为1…N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果
相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱
Input
输入两个整数M,N.1<=M<=10^8,1<=N<=10^12
Output
可能越狱的状态数,模100003取余
Sample Input
2 3
Sample Output
6
HINT
6种状态为(000)(001)(011)(100)(110)(111)
Source
总状态为M^N 不发生越狱的有M*(M-1)^(N-1)
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 8811 Solved: 3812
[Submit][Status][Discuss]
Description
监狱有连续编号为1…N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果
相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱
Input
输入两个整数M,N.1<=M<=10^8,1<=N<=10^12
Output
可能越狱的状态数,模100003取余
Sample Input
2 3
Sample Output
6
HINT
6种状态为(000)(001)(011)(100)(110)(111)
Source
总状态为M^N 不发生越狱的有M*(M-1)^(N-1)
#include<bits/stdc++.h> using namespace std; typedef long long ull; const ull mod = 100003; ull po(ull a,ull b) { ull ret=1; while(b>0) { if(b&1)ret=(ret%mod*a%mod)%mod; a=(a%mod*a%mod)%mod; b>>=1; } return ret; } signed main() { ull n,m; cin>>m>>n; cout<<(po(m,n)-(m%mod)*(po(m-1,n-1))%mod+mod)%mod; return 0; }
相关文章推荐
- [BZOJ1008][HNOI2008]越狱(数学相关)
- 越狱[HNOI2008,bzoj1008]
- 【bzoj1008】[HNOI2008]越狱
- BZOJ 1008([HNOI2008]越狱-等比数列求和)
- [组合数学]BZOJ 1008——[HNOI2008]越狱
- BZOJ 1008: [HNOI2008]越狱 快速幂
- bzoj1008: [HNOI2008]越狱 数学
- BZOJ 1008 [HNOI2008] 越狱
- BZOJ 1008: [HNOI2008]越狱
- bzoj1008 [HNOI2008]越狱
- BZOJ 1008: [HNOI2008]越狱
- 【bzoj1008】[HNOI2008]越狱
- BZOJ1008:[HNOI2008]越狱——题解
- BZOJ 1008: [HNOI2008]越狱 计数原理
- 【bzoj1008】[HNOI2008]越狱
- bzoj 1008: [HNOI2008]越狱 简单组合数学
- [BZOJ1008] [HNOI2008]越狱
- BZOJ 1008: [HNOI2008]越狱 题解
- 【BZOJ】1008: [HNOI2008]越狱
- 【BZOJ1008】【HNOI2008】越狱