Problem p02990 (C++)

Buggy submission (status: Runtime Error):
/*||>>>> Praveen Ojha <<<<>>>> 30 June 2019 <<<<>>>> 01:09:32 <<<<||*/
// #pragma GCC optimize("Ofast") //(Very Fast but Inaccurate)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// //(Small operations in many loops) #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18 + 5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define __                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define PRINT_TIME                                                             \
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int, int> pii;
// Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 2200;
int fact[N];
inline int powermod(int a, int n) {
  int result = 1;
  a = a % mod;
  while (n > 0) {
    if (n & 1)
      result = (a * result) % mod;
    a = (a * a) % mod;
    n /= 2;
  }
  return result;
}
inline int modInv(int x) { return powermod(x, mod - 2); }
inline int ncr(int n, int r) {
  int cur = fact[n];
  cur = (cur * modInv(fact[n - r])) % mod;
  cur = (cur * modInv(fact[r])) % mod;
  return cur;
}
int32_t main() {
  __ int n, k;
  cin >> n >> k;
  int red = n - k;
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
  }
  for (int i = 1; i <= k; i++) {
    cout << ncr(red + 1, i) * ncr(k - 1, i - 1) % mod << "\n";
  }
  return 0;
}

Fixed submission:
/*||>>>> Praveen Ojha <<<<>>>> 30 June 2019 <<<<>>>> 01:09:32 <<<<||*/
// #pragma GCC optimize("Ofast") //(Very Fast but Inaccurate)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// //(Small operations in many loops) #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18 + 5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define __                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define PRINT_TIME                                                             \
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int, int> pii;
// Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 2200;
int fact[N];
inline int powermod(int a, int n) {
  int result = 1;
  a = a % mod;
  while (n > 0) {
    if (n & 1)
      result = (a * result) % mod;
    a = (a * a) % mod;
    n /= 2;
  }
  return result;
}
inline int modInv(int x) { return powermod(x, mod - 2); }
inline int ncr(int n, int r) {
  if (n < r)
    return 0;
  int cur = fact[n];
  cur = (cur * modInv(fact[n - r])) % mod;
  cur = (cur * modInv(fact[r])) % mod;
  return cur;
}
int32_t main() {
  __ int n, k;
  cin >> n >> k;
  int red = n - k;
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
  }
  for (int i = 1; i <= k; i++) {
    cout << ncr(red + 1, i) * ncr(k - 1, i - 1) % mod << "\n";
  }
  return 0;
}