Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto &i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y)                                                            \
  cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T> using pq = priority_queue<T>;
template <typename T> using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;
using ll = long long;

template <typename T1, typename T2>
ostream &operator<<(ostream &stream, const pair<T1, T2> &p) {
  return stream << p.first << " " << p.second;
}
template <typename T> void print(const vector<vector<T>> matrix) {
  repall(vec, matrix) print(vec);
}
template <typename T> void print(const vector<T> vec) {
  unsigned int len = vec.size();
  rep(i, len - 1) cout << vec[i] << ' ';
  cout << vec[len - 1] << '\n';
}
template <typename Arg> void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
  cout << head << " ";
  print(args...);
}
template <typename T> T sum_(vector<T> vec, T init = 0) {
  return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T> void init(vector<T> &v) { rep(i, v.size()) cin >> v[i]; }

template <typename T, typename U> void init(vector<T> &v, vector<U> &w) {
  assert(v.size() == w.size());
  rep(i, v.size()) cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

class ModuloCombination {
  using ll = long long;
  ll mod, len;
  std::vector<ll> f, rf;

  ll inv(ll x);

public:
  ModuloCombination(long long mod_ = 1000000007);
  ll c(int n, int k);
  ll getMod() { return mod; }
};

ll ModuloCombination::inv(ll x) {
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % mod;
    y = y * y % mod;
    k /= 2;
  }
  return res;
}

ModuloCombination::ModuloCombination(ll mod_)
    : mod(mod_), len(101010), f(std::vector<ll>(len)),
      rf(std::vector<ll>(len)) {
  f[0] = 1;
  for (int i = 0; i < len - 1; i++)
    f[i + 1] = f[i] * (i + 1) % mod;
  for (int i = 0; i < len; i++)
    rf[i] = inv(f[i]);
}

ll ModuloCombination::c(int n, int k) {
  ll a = f[n];
  ll b = rf[n - k];
  ll c = rf[k];
  ll bc = (b * c) % mod;
  return (a * bc) % mod;
}

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  ModuloCombination com;
  For(i, 1, k) { print((com.c(n - k + 1, i) * com.c(k - 1, i - 1)) % MOD); }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto &i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y)                                                            \
  cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T> using pq = priority_queue<T>;
template <typename T> using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;
using ll = long long;

template <typename T1, typename T2>
ostream &operator<<(ostream &stream, const pair<T1, T2> &p) {
  return stream << p.first << " " << p.second;
}
template <typename T> void print(const vector<vector<T>> matrix) {
  repall(vec, matrix) print(vec);
}
template <typename T> void print(const vector<T> vec) {
  unsigned int len = vec.size();
  rep(i, len - 1) cout << vec[i] << ' ';
  cout << vec[len - 1] << '\n';
}
template <typename Arg> void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
  cout << head << " ";
  print(args...);
}
template <typename T> T sum_(vector<T> vec, T init = 0) {
  return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T> void init(vector<T> &v) { rep(i, v.size()) cin >> v[i]; }

template <typename T, typename U> void init(vector<T> &v, vector<U> &w) {
  assert(v.size() == w.size());
  rep(i, v.size()) cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

class ModuloCombination {
  using ll = long long;
  ll mod, len;
  std::vector<ll> f, rf;

  ll inv(ll x);

public:
  ModuloCombination(long long mod_ = 1000000007);
  ll c(int n, int k);
  ll getMod() { return mod; }
};

ll ModuloCombination::inv(ll x) {
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % mod;
    y = y * y % mod;
    k /= 2;
  }
  return res;
}

ModuloCombination::ModuloCombination(ll mod_)
    : mod(mod_), len(101010), f(std::vector<ll>(len)),
      rf(std::vector<ll>(len)) {
  f[0] = 1;
  for (int i = 0; i < len - 1; i++)
    f[i + 1] = f[i] * (i + 1) % mod;
  for (int i = 0; i < len; i++)
    rf[i] = inv(f[i]);
}

ll ModuloCombination::c(int n, int k) {
  ll a = f[n];
  ll b = rf[n - k];
  ll c = rf[k];
  ll bc = (b * c) % mod;
  return (a * bc) % mod;
}

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  ModuloCombination com;
  For(i, 1, k) {
    if (n - k + 1 < i)
      print(0);
    else
      print((com.c(n - k + 1, i) * com.c(k - 1, i - 1)) % MOD);
  }

  return 0;
}