Problem p02990 (C++)

Buggy submission (status: Runtime Error):
// Charan Sriramula

#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg = 22;
const ll N = 2e5 + 5;
const ll M = 5e8;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double PI = 3.14159265358979323846;

#define is(n) scanf("%d", &n)
#define io(n) printf("%d\n", n)
#define ls(n) scanf("%lld", &n)
#define lo(n) printf("%lld\n", n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
#define GCD(a, b) __gcd((a), (b))
#define all(v) v.begin(), v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a, b) ((a) * (b)) / GCD((a), (b))
#define fast                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
template <typename T> T power(T x, T y, ll m) {
  T ans = 1;
  while (y > 0) {
    if (y & 1LL)
      ans = (ans * x) % m;
    y >>= 1LL;
    x = (x * x) % m;
  }
  return ans % m;
}

inline ll mul(ll a, ll b, ll p) { return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p) {
  ll c = a - b;
  if (c < 0)
    c += p;
  return c;
}
inline ll add(ll a, ll b, ll p) {
  ll c = a + b;
  if (c > p)
    c -= p;
  return c;
}

#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl

ll n, k, fac[N];

ll nCr(ll m, ll r) {
  ll num = fac[m] % mod;
  ll den = ((fac[m - r] % mod) * (fac[r] % mod)) % mod;
  ll minv = power(den, mod - 2, mod);
  ll fin = ((num % mod) * (minv % mod)) % mod;
  return fin;
}

int main() {
  cin >> n >> k;
  fac[0] = 1;
  for (ll i = 1; i <= 4005; i++) {
    fac[i] = ((fac[i - 1] % mod) * (i % mod)) % mod;
  }
  for (ll i = 1; i <= k; i++) {
    ll x = nCr(n - k + 1, i);
    ll y = nCr(k - 1, i - 1);
    x = mul(x, y, mod);
    cout << x << endl;
  }
}

Fixed submission:
// Charan Sriramula

#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg = 22;
const ll N = 2e5 + 5;
const ll M = 5e8;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double PI = 3.14159265358979323846;

#define is(n) scanf("%d", &n)
#define io(n) printf("%d\n", n)
#define ls(n) scanf("%lld", &n)
#define lo(n) printf("%lld\n", n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
#define GCD(a, b) __gcd((a), (b))
#define all(v) v.begin(), v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a, b) ((a) * (b)) / GCD((a), (b))
#define fast                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
template <typename T> T power(T x, T y, ll m) {
  T ans = 1;
  while (y > 0) {
    if (y & 1LL)
      ans = (ans * x) % m;
    y >>= 1LL;
    x = (x * x) % m;
  }
  return ans % m;
}

inline ll mul(ll a, ll b, ll p) { return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p) {
  ll c = a - b;
  if (c < 0)
    c += p;
  return c;
}
inline ll add(ll a, ll b, ll p) {
  ll c = a + b;
  if (c > p)
    c -= p;
  return c;
}

#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl

ll n, k, fac[N];

ll nCr(ll m, ll r) {
  if (m < r) {
    return 0;
  }
  ll num = fac[m] % mod;
  ll den = ((fac[m - r] % mod) * (fac[r] % mod)) % mod;
  ll minv = power(den, mod - 2, mod);
  ll fin = ((num % mod) * (minv % mod)) % mod;
  return fin;
}

int main() {
  cin >> n >> k;
  fac[0] = 1;
  for (ll i = 1; i <= 4005; i++) {
    fac[i] = ((fac[i - 1] % mod) * (i % mod)) % mod;
  }
  for (ll i = 1; i <= k; i++) {
    ll x = nCr(n - k + 1, i);
    ll y = nCr(k - 1, i - 1);
    x = mul(x, y, mod);
    cout << x << endl;
  }
}