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

本文通过一个具体的组合数学问题实例,展示了如何利用简单的算法解决问题,并提供了代码实现。主要涉及了幂运算和组合计数的基本概念。

原题链接: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;
}

 

转载于:https://www.cnblogs.com/HarryGuo2012/p/4845345.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值