1008: [HNOI2008]越狱

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 10503  Solved: 4558
[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)*(m-1)..*(m-1) 也就是m * (m-1)^(n-1)。由于 m 和 n 比较大,所以要用快速幂。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-3;
const int maxn = 2e5 + 10;
const int maxm = 3e5 + 10;
const int mod = 100003;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} LL fast_pow(LL a, LL n){
LL res = 1;
a %= mod;
while(n){
if(n&1) res = res * a % mod;
n >>= 1;
a = a * a % mod;
}
return res;
} int main(){
LL n, m;
scanf("%lld %lld", &m, &n);
LL ans = fast_pow(m, n) - m * fast_pow(m-1, n-1) % mod;
ans = (ans % mod + mod) % mod;
printf("%lld\n", ans);
return 0;
}

  

最新文章

  1. 一个简单确非常实用的javascript函数
  2. OC的封装、继承与多态
  3. shell awk入门
  4. AC自动机 - 多模式串匹配问题的基本运用 + 模板题 --- HDU 2222
  5. Cannot spawn... TortoisePlink
  6. Hadoop基本概念
  7. 希望获取到页面中所有的checkbox怎么做?
  8. fastq,sam文件一些小结(持续补充。。。)
  9. python selenium 自动化测试web
  10. IDEA 创建包和类及基本操作
  11. ubuntu下,python2.7安装mysqlldb驱动方法
  12. css3用到知识点小结
  13. Hibernate(链接数据库方便得多)!
  14. RFID的winform程序心得2
  15. maven多环境参数配置
  16. PostgreSQL之连接数修改
  17. 【【C++ Primer 第15章】 虚析构函数
  18. mybatis example 使用AND 和OR 联合查询
  19. NS3 使用NS3工具PyViz
  20. C# iTextSharp 生成 PDF

热门文章

  1. C++ 实现的netstat -an 的功能&lt;转&gt;-目的为获取rtmp推流地址如果是域名的话查看1935的ip
  2. dapper.net 转载
  3. git cherry-pick基本使用
  4. fiddler无法抓取chrome解决方法
  5. Numpy随机数
  6. TensorFlow RNN MNIST字符识别演示快速了解TF RNN核心框架
  7. SOA (面向服务的架构)
  8. 深入MySQL用户自定义变量
  9. HttpClient 发送 HTTP、HTTPS
  10. SVN服务器端的安装和配置