Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define rep1(i, n) for (int i = 1; i <= int(n); ++i)

class modint {
public:
  using ll = long long;
  ll num;
  static const ll MOD = 1e9 + 7;
  static vector<modint> factorial;

  modint() : num(0){};
  modint(ll n_) : num((n_ + MOD) % MOD) {}
  modint(const modint &r) : num(r.num) {}
  operator ll() const { return (num + MOD) % MOD; }
  friend istream &operator>>(istream &is, modint &r) {
    ll num_;
    is >> num_;
    r = num_;
    return is;
  }
  modint operator+(const modint &r) const { return modint(num + r.num); }
  modint operator-(const modint &r) const { return modint(num - r.num); }
  modint operator*(const modint &r) const { return modint(num * r.num); }

  template <typename T> modint operator^(const T &r) const {
    if (r == 0)
      return 1;
    return (((*this) * (*this)) ^ (r / 2)) * modint(r & 1 ? num : 1);
  }
  modint operator/(const modint &r) const { return num * (r ^ (MOD - 2)); }

  modint operator+=(const modint &r) { return *this = *this + r; }
  modint operator-=(const modint &r) { return *this = *this - r; }
  modint operator*=(const modint &r) { return *this = *this * r; }
  modint operator/=(const modint &r) { return *this = *this / r; }

  template <typename T> modint operator^=(const T &r) {
    return *this = *this ^ r;
  }

  static modint pow(const modint x, ll r) { return x ^ r; }

  static modint fact(int n) {
    if ((int)factorial.size() <= n)
      factorial.resize(n + 1);
    if (factorial[n])
      return factorial[n];
    if (n == 0)
      return 1;
    return factorial[n] = modint(n) * fact(n - 1);
  }

  static modint C(ll n, ll r) {
    return n >= r ? fact(n) / (fact(n - r) * fact(r)) : modint(0);
  }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n, r) modint::C(n, r)
#define H(a, b) C(a + b, a)

int main(void) {
  ll n, k;
  cin >> n >> k;
  rep1(i, k) {
    cout << modint::C(k - 1, i - 1) * modint::H((n - k) - (i - 1), i) << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define rep1(i, n) for (int i = 1; i <= int(n); ++i)

class modint {
public:
  using ll = long long;
  ll num;
  static const ll MOD = 1e9 + 7;
  static vector<modint> factorial;

  modint() : num(0){};
  modint(ll n_) : num((n_ + MOD) % MOD) {}
  modint(const modint &r) : num(r.num) {}
  operator ll() const { return (num + MOD) % MOD; }
  friend istream &operator>>(istream &is, modint &r) {
    ll num_;
    is >> num_;
    r = num_;
    return is;
  }
  modint operator+(const modint &r) const { return modint(num + r.num); }
  modint operator-(const modint &r) const { return modint(num - r.num); }
  modint operator*(const modint &r) const { return modint(num * r.num); }

  template <typename T> modint operator^(const T &r) const {
    if (r == 0)
      return 1;
    return (((*this) * (*this)) ^ (r / 2)) * modint(r & 1 ? num : 1);
  }
  modint operator/(const modint &r) const { return num * (r ^ (MOD - 2)); }

  modint operator+=(const modint &r) { return *this = *this + r; }
  modint operator-=(const modint &r) { return *this = *this - r; }
  modint operator*=(const modint &r) { return *this = *this * r; }
  modint operator/=(const modint &r) { return *this = *this / r; }

  template <typename T> modint operator^=(const T &r) {
    return *this = *this ^ r;
  }

  static modint pow(const modint x, ll r) { return x ^ r; }

  static modint fact(int n) {
    if ((int)factorial.size() <= n)
      factorial.resize(n + 1);
    if (factorial[n])
      return factorial[n];
    if (n == 0)
      return 1;
    return factorial[n] = modint(n) * fact(n - 1);
  }

  static modint C(ll n, ll r) {
    return n >= r ? fact(n) / (fact(n - r) * fact(r)) : modint(0);
  }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n, r) modint::C(n, r)
#define H(a, b) C(a + b, a)

int main(void) {
  ll n, k;
  cin >> n >> k;
  rep1(i, k) {
    if ((n - k) - (i - 1) < 0) {
      cout << 0 << endl;
    } else {
      cout << modint::C(k - 1, i - 1) * modint::H((n - k) - (i - 1), i) << endl;
    }
  }
  return 0;
}