cpplib

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

View the Project on GitHub edge2992/cpplib

:heavy_check_mark: test/comb.aoj_DPL_5_E.test.cpp

Depends on

Code

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

#include <iostream>
#include "../math/comb.hpp"

int main() {
    int n, k; std::cin >> n >> k;
    combination comb(1009);
    std::cout << comb(k, n) << std::endl;
}
#line 1 "test/comb.aoj_DPL_5_E.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_E"

#include <iostream>
#line 3 "math/comb.hpp"
#include <vector>
#line 3 "math/mint.hpp"
using namespace std;
const int mod = 1000000007;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a){ return mint(*this) += a; }
  mint operator-(const mint a){ return mint(*this) -= a; }
  mint operator*(const mint a){ return mint(*this) *= a; }
  mint pow(long long t) const {
    if(!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint& a) { return *this *= a.inv(); }
  mint operator/(const mint& a){ return mint(*this) /= a; }
};
mint pow(mint a, long long b){
    return a.pow(b);
}
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
#line 5 "math/comb.hpp"
using namespace std;

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
#line 5 "test/comb.aoj_DPL_5_E.test.cpp"

int main() {
    int n, k; std::cin >> n >> k;
    combination comb(1009);
    std::cout << comb(k, n) << std::endl;
}
Back to top page