首页 > 其他 > 详细

BZOJ 1008: [HNOI2008]越狱 组合数学

时间:2015-09-29 01:07:41      阅读:205      评论:0      收藏:0      [点我收藏+]

原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1008

题解:

就很傻逼的组合数学啊。。。

$$ans=M^N-M*(M-1)^{(N-1)}$$

代码:

/**************************************************************
    Problem: 1008
    User: HarryGuo2012
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1272 kb
****************************************************************/
 
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
 
typedef long long ll;
 
const ll mod=100003;
 
ll Pow(ll a,ll b) {
    ll res = 1;
    while (b) {
        if (b & 1)res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}
 
ll M,N;
 
int main() {
    scanf("%lld%lld", &M, &N);
    printf("%lld\n", (M*mod + Pow(M, N) - M * Pow(M - 1, N - 1)) % mod);
    return 0;
}

 

BZOJ 1008: [HNOI2008]越狱 组合数学

原文:http://www.cnblogs.com/HarryGuo2012/p/4845345.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!