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

BZOJ 1008: [HNOI2008]越狱 水

时间:2015-05-09 22:10:43      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:


BZOJ难得的水题

1008: [HNOI2008]越狱

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 4977  Solved: 2149
[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

[Submit][Status][Discuss]


/* ***********************************************
Author        :CKboss
Created Time  :2015年05月09日 星期六 16时24分47秒
File Name     :BZOJ1008.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long int LL;
const LL mod=100003;

LL m,n;

LL quickPow(LL a,LL n)
{
	LL e=1LL;
	while(n)
	{
		if(n&1) e=(a*e)%mod;
		a=(a*a)%mod;
		n=n>>1;
	}
	return e%mod;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	scanf("%lld%lld",&m,&n);
	LL ans=(quickPow(m,n)+mod-(m*quickPow(m-1,n-1))%mod)%mod;
	printf("%lld\n",ans);
    
    return 0;
}


BZOJ 1008: [HNOI2008]越狱 水

标签:

原文地址:http://blog.csdn.net/ck_boss/article/details/45604741

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