BZOJ1008: [HNOI2008] Prison Break (fast power)

topic:

1008: [HNOI2008] escape

Resolution:

Out of the water problem solutionOther questions too much trouble do not want to write, to write about this topic zz
Using the principle of multiplication, a total of \ (m ^ n \) method detained criminals, the adjacent mutually different methods \ (m * (m-1
) ^ {n-1} \) so the answer is \ (m ^ nm * (m-1) ^ {n-1} \)

Code:

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 100003;

int n, m;

int qpow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1, a = (a * a) % mod;
    }
    return ans;
}

signed main() {
    cin >> m >> n;
    int a = (qpow(m - 1, n - 1) * (m % mod)) % mod;
    cout << (qpow(m, n) - a + mod) % mod;
}

Guess you like

Origin www.cnblogs.com/lykkk/p/11402319.html