BZOJ 1008: [HNOI2008]越狱 水


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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值