[bzoj1008] [HNOI2008]越狱

Solution

拿到这道题,想了半天,不知道怎么找可能越狱的状态数。
其实只要换个思路我们只要找到不会越狱的状态数就行了。
第一个人有m种可能,后面的n-1个人每个人要和前面不同,有m-1种可能。
然后用快速幂搞一搞就好了。

Code

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;

const int mod = 100003;
LL n, m;

int mul(LL x, LL k) {
	int res = 1;
	for(; k; k>>=1) {if(k&1)res = res * x % mod; x = x * x % mod;}
	return res;
}

int main() {
	scanf("%lld%lld", &m, &n);
	printf("%d\n", (mul(m, n - 1) - mul(m-1, n-1) + mod) * m % mod);
	return 0;
}
posted @ 2017-01-14 16:48  ZegWe  阅读(209)  评论(0编辑  收藏  举报