Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }
int modPow(long long a, long long n, long long p) {
  if (n == 0)
    return 1; // 0乗にも対応する場合
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
  fact.resize(n + 5);
  factinv.resize(n + 5);
  inv.resize(n + 5);
  fact.at(0) = fact.at(1) = 1;
  factinv.at(0) = factinv.at(1) = 1;
  inv.at(1) = 1;
  for (ll i = 2; i < n + 5; i++) {
    fact.at(i) = (fact.at(i - 1) * i) % mod;
    inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
    factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
  }
}
ll nCk(ll n, ll k) {
  return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}

int main() {

  ll N, K;
  cin >> N >> K;
  prenCkModp(N);
  rep(i, K) { cout << (nCk(N - K + 1, i + 1) * nCk(K - 1, i)) % mod << endl; }
}


Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }
int modPow(long long a, long long n, long long p) {
  if (n == 0)
    return 1; // 0乗にも対応する場合
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
  fact.resize(n + 5);
  factinv.resize(n + 5);
  inv.resize(n + 5);
  fact.at(0) = fact.at(1) = 1;
  factinv.at(0) = factinv.at(1) = 1;
  inv.at(1) = 1;
  for (ll i = 2; i < n + 5; i++) {
    fact.at(i) = (fact.at(i - 1) * i) % mod;
    inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
    factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
  }
}
ll nCk(ll n, ll k) {
  if (n < k)
    return 0;
  else {
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
  }
}

int main() {

  ll N, K;
  cin >> N >> K;
  prenCkModp(N);
  rep(i, K) { cout << (nCk(N - K + 1, i + 1) * nCk(K - 1, i)) % mod << endl; }
}