Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define MOD 1000000007LL
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
typedef priority_queue<ll, vector<ll>, greater<ll>> gpq_int; // sho-jun
typedef priority_queue<ll, vector<ll>, less<ll>> lpq_int;    // ko-jun

ll mod(ll a, ll mod) {
  ll res = a % mod;
  if (res < 0)
    res = res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }

bool is_prime(ll n) {
  ll i = 2;
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  bool res = true;
  while (i * i < n) {
    if (n % i == 0) {
      res = false;
    }
    i = i + 1;
  }

  // if(i==1)res = false;
  if (n % i == 0)
    res = false;
  return res;
}

void fact(ll a, ll fact[]) {
  ll i = 2;
  ll original = a;
  fact[1] = 1;
  rep(i, 1000000 - 1) {
    int ii = i + 2;
    while (a % ii == 0) {
      fact[ii] += 1;
      a = a / ii;
    }
  }
  if (a > 1) {
    fact[0] = a;
  }

  return;
}

ll N, K;
ll frac[10010];
ll fracinv[10010];

ll comb(ll n, ll k) {
  ll tmp = 1;
  tmp = mod(tmp * frac[n], MOD);
  tmp = mod(tmp * fracinv[k], MOD);
  tmp = mod(tmp * fracinv[n - k], MOD);
  return tmp;
}

int main() {
  cin >> N >> K;
  frac[0] = 1;
  fracinv[0] = 1;
  rep(i, 10000) {
    frac[i + 1] = mod(frac[i] * (i + 1), MOD);
    fracinv[i + 1] = modinv(frac[i + 1], MOD);
  }

  for (ll i = 1; i <= K; i++) {
    ll tmp = comb(N - K + 1, i);
    ll tmp2 = comb(K - 1, i - 1);
    cout << mod(tmp * tmp2, MOD) << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define MOD 1000000007LL
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
typedef priority_queue<ll, vector<ll>, greater<ll>> gpq_int; // sho-jun
typedef priority_queue<ll, vector<ll>, less<ll>> lpq_int;    // ko-jun

ll mod(ll a, ll mod) {
  ll res = a % mod;
  if (res < 0)
    res = res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }

bool is_prime(ll n) {
  ll i = 2;
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  bool res = true;
  while (i * i < n) {
    if (n % i == 0) {
      res = false;
    }
    i = i + 1;
  }

  // if(i==1)res = false;
  if (n % i == 0)
    res = false;
  return res;
}

void fact(ll a, ll fact[]) {
  ll i = 2;
  ll original = a;
  fact[1] = 1;
  rep(i, 1000000 - 1) {
    int ii = i + 2;
    while (a % ii == 0) {
      fact[ii] += 1;
      a = a / ii;
    }
  }
  if (a > 1) {
    fact[0] = a;
  }

  return;
}

ll N, K;
ll frac[10010];
ll fracinv[10010];

ll comb(ll n, ll k) {
  ll tmp = 1;
  tmp = mod(tmp * frac[n], MOD);
  tmp = mod(tmp * fracinv[k], MOD);
  tmp = mod(tmp * fracinv[n - k], MOD);
  return tmp;
}

int main() {
  cin >> N >> K;
  frac[0] = 1;
  fracinv[0] = 1;
  rep(i, 10000) {
    frac[i + 1] = mod(frac[i] * (i + 1), MOD);
    fracinv[i + 1] = modinv(frac[i + 1], MOD);
  }

  for (ll i = 1; i <= K; i++) {
    if (N - K + 1 < i) {
      cout << 0 << endl;
    } else {
      ll tmp = comb(N - K + 1, i);
      ll tmp2 = comb(K - 1, i - 1);
      cout << mod(tmp * tmp2, MOD) << endl;
    }
  }
}