Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b)                                                            \
  {                                                                            \
    if (a < b)                                                                 \
      a = b;                                                                   \
  }
#define chmin(a, b)                                                            \
  {                                                                            \
    if (a > b)                                                                 \
      a = b;                                                                   \
  }
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }

ll moP(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      moC(res, *, x);
    moC(x, *, x);
    n >>= 1;
  }
  return res;
}

ll fa[2020], rfa[2020];

ll C(ll n, ll k) {
  if (k == 0)
    return 1;
  if (n == k)
    return 1;
  return fa[n] * rfa[n - k] % MOD * rfa[k] % MOD;
}

int main(void) {
  ll N, K;
  cin >> N >> K;
  ll i;

  fa[0] = 1;
  rfa[0] = 1;
  for (i = 1; i <= 2000; i++) {
    fa[i] = i * fa[i - 1] % MOD;
    rfa[i] = moP(fa[i], MOD - 2);
  }

  for (i = 1; i <= K; i++) {
    pt(C(N - K + 1, i) * C(K - 1, i - 1) % MOD);
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b)                                                            \
  {                                                                            \
    if (a < b)                                                                 \
      a = b;                                                                   \
  }
#define chmin(a, b)                                                            \
  {                                                                            \
    if (a > b)                                                                 \
      a = b;                                                                   \
  }
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }

ll moP(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      moC(res, *, x);
    moC(x, *, x);
    n >>= 1;
  }
  return res;
}

ll fa[2020], rfa[2020];

ll C(ll n, ll k) {
  if (n < k)
    return 0;
  if (k < 0)
    return 0;
  if (k == 0)
    return 1;
  if (n == k)
    return 1;
  return fa[n] * rfa[n - k] % MOD * rfa[k] % MOD;
}

int main(void) {
  ll N, K;
  cin >> N >> K;
  ll i;

  fa[0] = 1;
  rfa[0] = 1;
  for (i = 1; i <= 2000; i++) {
    fa[i] = i * fa[i - 1] % MOD;
    rfa[i] = moP(fa[i], MOD - 2);
  }

  for (i = 1; i <= K; i++) {
    pt(C(N - K + 1, i) * C(K - 1, i - 1) % MOD);
  }
}