Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repR(i, n) for (ll i = n; i >= 0; ++i)
#define FDS(i, n) for (ll i = 0; i < n; ++i)
#define FDSR(i, n) for (ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;
template <typename Typell> Typell G_C_D(Typell a, Typell b) {
  if (a < 0)
    a = -a;
  if (b < 0)
    b = -b;
  while (b != 0) {
    a %= b;
    if (a == 0)
      return b;
    b %= a;
  }
  return a;
}
template <typename Typell> Typell G_C_D(const std::vector<Typell> &list) {
  Typell a = list[0];
  for (size_t i = 1; i < list.size(); ++i) {
    a = G_C_D(a, list[i]);
  }
  return a;
}
template <typename Typell> Typell L_C_M(Typell a, Typell b) {
  if (a == 0 && b == 0)
    return 0;
  return a / G_C_D(a, b) * b;
}
template <typename Typell> Typell L_C_M(const std::vector<Typell> &list) {
  Typell a = list[0];
  for (size_t i = 1; i < list.size(); ++i) {
    a = L_C_M(a, list[i]);
  }
  return a;
}
const int mod = 1000000007;

long long inv[9999999], fact[9999999], ifact[9999999];
long long comb(ll n, ll k) {
  return fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

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

  inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
  for (int i = 2; i < 9999999; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    fact[i] = fact[i - 1] * i % mod;
    ifact[i] = ifact[i - 1] * inv[i] % mod;
  }

  ll N, K;
  cin >> N >> K;
  ll B = K;
  ll A = N - K;
  for (int i = 1; i <= K; i++) {
    ll ans = 0;
    ans = comb(A + 1, i) * comb(B - 1, i - 1);
    ans %= mod;
    cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repR(i, n) for (ll i = n; i >= 0; ++i)
#define FDS(i, n) for (ll i = 0; i < n; ++i)
#define FDSR(i, n) for (ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;
template <typename Typell> Typell G_C_D(Typell a, Typell b) {
  if (a < 0)
    a = -a;
  if (b < 0)
    b = -b;
  while (b != 0) {
    a %= b;
    if (a == 0)
      return b;
    b %= a;
  }
  return a;
}
template <typename Typell> Typell G_C_D(const std::vector<Typell> &list) {
  Typell a = list[0];
  for (size_t i = 1; i < list.size(); ++i) {
    a = G_C_D(a, list[i]);
  }
  return a;
}
template <typename Typell> Typell L_C_M(Typell a, Typell b) {
  if (a == 0 && b == 0)
    return 0;
  return a / G_C_D(a, b) * b;
}
template <typename Typell> Typell L_C_M(const std::vector<Typell> &list) {
  Typell a = list[0];
  for (size_t i = 1; i < list.size(); ++i) {
    a = L_C_M(a, list[i]);
  }
  return a;
}
const int mod = 1000000007;

long long inv[9999999], fact[9999999], ifact[9999999];
long long comb(ll n, ll k) {
  return fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

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

  inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
  for (int i = 2; i < 9999999; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    fact[i] = fact[i - 1] * i % mod;
    ifact[i] = ifact[i - 1] * inv[i] % mod;
  }

  ll N, K;
  cin >> N >> K;
  ll B = K;
  ll A = N - K;
  for (int i = 1; i <= K; i++) {
    ll ans = 0;
    if (A + 1 >= i && B - 1 >= i - 1) {
      ans = comb(A + 1, i) * comb(B - 1, i - 1);
    } else
      ans = 0;
    ans %= mod;
    cout << ans << endl;
  }
}