Problem p02990 (C++)

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

#define int long long
#define ll long long
#define vi vector<int>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i > b; i--)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less
<pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
/// X.order_of_key("key")

#define deb(x) cerr << #x << " : " << x << "\n";
#ifndef local
#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n, k;

int fac[5000];
int expo(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    x = (x * x) % MOD;
    y /= 2;
  }
  return res;
}
int Inv(int r) { return expo(r, MOD - 2); }
int ncr(int n, int r) {
  ///	if (r>n || n<=0||r<0)return 0;
  if (r == 0 || r == n)
    return 1;
  if (r == 1 || r == n - 1)
    return n;
  return (((fac[n] * Inv(fac[n - r])) % MOD) * Inv(fac[r])) % MOD;
}
void solve() {

  fac[0] = 1;
  rep(i, 1, 5000) fac[i] = (fac[i - 1] * i) % MOD;

  cin >> n >> k;
  if (n == k) {
    cout << "1\n";
    rep(i, 0, k - 1) cout << 0 << "\n";
    return;
  }

  rep(i, 1, k + 1) {
    cout << (ncr(n - k + 1, i) * ncr(k - 1, i - 1)) % MOD << "\n";
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef local
  /// freopen("input.txt","r",stdin);
  /// freopen("output.txt","w",stdout);
  clock_t qwertyuiop = clock();
#endif

  int t = 1;
  // cin>>t;

  rep(a, 0, t) {
    /// cout<<"Case #"<<a+1<<": ";
    solve();
  }
#ifdef local
  {
    qwertyuiop = clock() - qwertyuiop;
    double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC;
    cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken
         << " seconds\n";
  }
#endif
}

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

#define int long long
#define ll long long
#define vi vector<int>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i > b; i--)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less
<pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
/// X.order_of_key("key")

#define deb(x) cerr << #x << " : " << x << "\n";
#ifndef local
#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n, k;

int fac[5000];
int expo(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    x = (x * x) % MOD;
    y /= 2;
  }
  return res;
}
int Inv(int r) { return expo(r, MOD - 2); }
int ncr(int n, int r) {
  if (r > n || n < 0 || r < 0)
    return 0;
  if (r == 0 || r == n)
    return 1;
  if (r == 1 || r == n - 1)
    return n;
  return (((fac[n] * Inv(fac[n - r])) % MOD) * Inv(fac[r])) % MOD;
}
void solve() {

  fac[0] = 1;
  rep(i, 1, 5000) fac[i] = (fac[i - 1] * i) % MOD;

  cin >> n >> k;
  if (n == k) {
    cout << "1\n";
    rep(i, 0, k - 1) cout << 0 << "\n";
    return;
  }

  rep(i, 1, k + 1) {
    cout << (ncr(n - k + 1, i) * ncr(k - 1, i - 1)) % MOD << "\n";
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef local
  /// freopen("input.txt","r",stdin);
  /// freopen("output.txt","w",stdout);
  clock_t qwertyuiop = clock();
#endif

  int t = 1;
  // cin>>t;

  rep(a, 0, t) {
    /// cout<<"Case #"<<a+1<<": ";
    solve();
  }
#ifdef local
  {
    qwertyuiop = clock() - qwertyuiop;
    double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC;
    cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken
         << " seconds\n";
  }
#endif
}