一道Lucas定理的板子题

一道Lucas定理的板子题

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll P = 1e9 + 7;
const int N = 3e6 + 100;

ll fac[N], inv[N];

inline ll C(int n, int m) {
    if (n < m)
        return 0;
    return fac[n] * inv[m] % P * inv[n - m] % P;
}

inline ll qpow(ll a, ll b, ll p) {
    ll res = 1;
    while (b) {
        if (b & 1)
            res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}



int main () {
    int n, m;
    ios::sync_with_stdio(false);
    cin >> m >> n;
    fac[0] = 1;
    for (int i = 1; i <= 2 * n; ++i)
        fac[i] = fac[i - 1] * i % P;
    inv[2 * n] = qpow(fac[2 * n], P - 2, P);
    for (int i = 2 * n - 1; i >= 0; --i)
        inv[i] = inv[i + 1] * (i + 1ll) % P;
     cout << C(n - 1, m - 1) << " " << C(n + m - 1, m - 1) << endl;
    return 0;
}

 https://www.cnblogs.com/fzl194/p/9095177.html

上一篇:K - Wand(组合数+错排公式)


下一篇:组合数学