Language: C++


#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long ll;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MAX = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    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];
  }
} comb(MAX);

ll f[MAX];
void init() 
{
    f[0] = 1;
    for(int i = 1; i < MAX; ++i) f[i] = (f[i - 1] * i) % mod;
}
 
 //! count the combination of distributing d people to r rooms
 mint dist(int r, int d)
 {
     return mint(f[d+r-1]) / (mint(f[r-1]) * mint(f[d]));
 }

//! count the combinations when d meaningful move takes place
 mint count(int n, int d)
 {
     mint c = comb(n, d); //! variation of empty rooms
     return c * dist(n-d, d);
 }


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);

    init();

    int n, k;
    cin >> n >> k;

    mint ans;

    for (int d = 0; d <= min(k, n-1); ++d) {
        ans += count(n, d);
    }

    cout << ans.x << endl;

    return 0;
}


Compiler output:
a.cc: In constructor 'combination::combination(int)':
a.cc:83:5: error: 'assert' was not declared in this scope
   83 |     assert(n < mod);
      |     ^~~~~~
a.cc:15:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   14 | #include <utility>
  +++ |+#include <cassert>
   15 |