Codevs 1851 越狱 2008年湖南省队选拔赛

61 篇文章 0 订阅
29 篇文章 0 订阅

1851 越狱 2008年湖南省队选拔赛
时间限制: 10 s
空间限制: 128000 KB
题目等级 : 大师 Master
题目描述 Description
监狱有连续编号为1…N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱
输入描述 Input Description
输入两个整数M,N.1<=M<=10^8,1<=N<=10^12
输出描述 Output Description
可能越狱的状态数,模100003取余
样例输入 Sample Input
2 3
样例输出 Sample Output
6
数据范围及提示 Data Size & Hint
6种状态为(000)(001)(011)(100)(110)(111)
分类标签 Tags
湖南 省队选拔赛 2008年

/*
组合数学.
总情况为m^n.
然后不相邻的有m*(m-1)^(n-1).
坑的是mod以后要保证ans>0. 
*/
#include<iostream>
#include<cstdio>
#define LL long long
#define mod 100003
using namespace std;
LL n,m,ans;
LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
    return x*f;
}
LL mi(LL a,LL b)
{
    LL tot=1;
    while(b)
    {
        if(b&1) tot=tot*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return tot;
}
int main()
{
    m=read(),n=read();
    ans=mi(m,n)%mod;
    LL x=m*mi(m-1,n-1)%mod;
    while(ans<x) ans+=mod;
    ans=(ans-x)%mod;
    cout<<ans;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值