[Bzoj1008] [HNOI2008] Jailbreak

Topic links: https://www.lydsy.com/JudgeOnline/problem.php?id=1008

Simple combination title count might escape program number equal to the total number of the program - the program number can not escape, then:

The total number of programs as: m n- .

We can not escape the program number m * (m-1) n-1 , (m types of individuals selected from a first method, after the individual has n-1 m-1 compounds selected method).

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const ll INF = 9e18 + 7;
const int maxn = 5e5 + 10;
inline ll read() {
    ll n = 0, f = 1; char ch = getchar();
    while (ch<'0' || ch>'9') { f = -1, ch = getchar(); }
    while (ch >= '0'&&ch <= '9') { n = n * 10 + ch - '0', ch = getchar(); }
    return n * f;
}
ll qpow(ll a, ll b, ll mod) {
    ll ans = 1;
    a %= mod;
    while (b) {
        if (b & 1)
            ans = ans * a%mod;
        a = a * a%mod;
        b >>= 1;
    }
    return ans;
}
int main() {
    ll m, n;
    m = read(), n = read();
    printf("%lld\n", (qpow(m, n, 100003) - m * qpow(m - 1, n - 1, 100003) % 100003 + 100003) % 100003);
}

 

Guess you like

Origin www.cnblogs.com/sainsist/p/11116422.html