Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ret2home/Library

:heavy_check_mark: test/Combination.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_E"

#include "math/Combination.cpp"

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	const int mod=1e9+7;
	Combination<mod>C;
	int n,k;cin>>n>>k;
	cout<<C.nCk(k,n)<<"\n";
}
#line 1 "test/Combination.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_E"

#line 2 "template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define REV(i, n) for (int i = n - 1; i > 0; i--)
#define all(v) v.begin(), v.end()
#define PL pair<ll, ll>
#define PI pair<int, int>
#define pi acos(-1)
#define len(s) (int)s.size()
#define compress(v) \
    sort(all(v));   \
    v.erase(unique(all(v)), v.end());
#define comid(v, x) lower_bound(all(v), x) - v.begin()

template<class T>
using prique=priority_queue<T,vector<T>,greater<>>;

template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmax(T &a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
constexpr ll inf = 3e18;
#line 3 "math/extgcd.cpp"

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return (x % m + m) % m;
}
#line 4 "math/modint.cpp"

template <int MOD>
struct mint {
    int32_t n;
    mint() : n(0) {}
    mint(ll x) : n(x >= 0 ? x % MOD : (MOD - (-x) % MOD) % MOD) {}

    mint &operator+=(const mint &p) {
        if ((n += p.n) >= MOD) n -= MOD;
        return *this;
    }
    mint &operator-=(const mint &p) {
        if ((n += MOD - p.n) >= MOD) n -= MOD;
        return *this;
    }
    mint &operator*=(const mint &p) {
        n = 1ll * n * p.n % MOD;
        return *this;
    }
    mint &operator/=(const mint &p) {
        *this *= p.inverse();
        return *this;
    }
    mint operator-() const { return mint(-n); }
    mint operator+(const mint &p) const { return mint(*this) += p; }
    mint operator-(const mint &p) const { return mint(*this) -= p; }
    mint operator*(const mint &p) const { return mint(*this) *= p; }
    mint operator/(const mint &p) const { return mint(*this) /= p; }
    bool operator==(const mint &p) const { return n == p.n; }
    bool operator!=(const mint &p) const { return n != p.n; }

    friend ostream &operator<<(ostream &os, const mint &p) {
        return os << p.n;
    }
    friend istream &operator>>(istream &is, mint &p) {
        int x;
        is >> x;
        p = mint(x);
        return is;
    }
    mint pow(int64_t x) const {
        mint res(1), mul(n);
        while (x > 0) {
            if (x & 1) res *= mul;
            mul *= mul;
            x >>= 1;
        }
        return res;
    }
    mint inverse() const {
        return mint(modinv(n,MOD));
    }
};
/*
@brief mod int
@docs docs/modint.md
*/
#line 3 "math/Combination.cpp"

template <int MOD>
struct Combination {
    using modint = mint<MOD>;
    vector<modint> perm, inv;

    Combination(int x = 1e6) {
        perm.resize(x);
        inv.resize(x);
        perm[0] = modint(1);
        REP(i, x + 1)
        perm[i] = perm[i - 1] * i;
        inv[x] = perm[x].pow(MOD - 2);
        for (int i = x - 1; i >= 0; i--) {
            inv[i] = inv[i + 1] * (i + 1);
        }
    }
    modint nCk(int x, int y) {
        if (x < y) return modint(0);
        return perm[x] * inv[x - y] * inv[y];
    }
};
/*
@brief Combination (nCk)
@docs docs/Combination.md
*/
#line 4 "test/Combination.test.cpp"

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	const int mod=1e9+7;
	Combination<mod>C;
	int n,k;cin>>n>>k;
	cout<<C.nCk(k,n)<<"\n";
}
Back to top page