Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
ll N, K;
ll fact[2010], fact_inv[2010];

// 逆元を求める
long long mod_inv(long long value) {

  long long b = MOD, u = 1, v = 0;

  while (b) {
    long long t = value / b;
    value -= t * b;
    swap(value, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0)
    u += MOD;

  return u;
}

void calc_fact() {
  fact[0] = 1;
  fact_inv[0] = 1;
  for (int i = 1; i < 2010; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= MOD;
    fact_inv[i] = mod_inv(fact[i]);
  }
}

ll comb(ll n, ll r) {
  if (r == 0)
    return 1;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

void solve() {

  cin >> N >> K;

  calc_fact();

  for (int i = 1; i <= K; i++) {

    ll tmp = comb(2, 1) * comb(1998, 2);

    ll ans = comb(K - 1, i - 1) * comb(N - K + 1, i) % MOD;
    cout << ans << endl;
  }

  return;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
ll N, K;
ll fact[2010], fact_inv[2010];

// 逆元を求める
long long mod_inv(long long value) {

  long long b = MOD, u = 1, v = 0;

  while (b) {
    long long t = value / b;
    value -= t * b;
    swap(value, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0)
    u += MOD;

  return u;
}

void calc_fact() {
  fact[0] = 1;
  fact_inv[0] = 1;
  for (int i = 1; i < 2010; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= MOD;
    fact_inv[i] = mod_inv(fact[i]);
  }
}

ll comb(ll n, ll r) {
  if (r == 0)
    return 1;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

void solve() {

  cin >> N >> K;

  calc_fact();

  for (int i = 1; i <= K; i++) {
    if (N - K + 1 < i) {
      cout << 0 << endl;
      continue;
    }
    ll ans = comb(K - 1, i - 1) * comb(N - K + 1, i) % MOD;
    cout << ans << endl;
  }

  return;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();

  return 0;
}