Problem p03253 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define init_random                                                            \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define start_routine                                                          \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  int begtime = clock();
#define end_routine                                                            \
  int endtime = clock();                                                       \
  cerr << endl                                                                 \
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC      \
       << " ms";                                                               \
  return 0
#define contests_de_diya_kar 0
#define PB push_back
#define MP make_pair
#define int long long
#define sd(n) scanf("%lld", &n)
#define pd(n) printf("%lld\n", n)
#define MOD ((long long)(1000 * 1000 * 1000 + 7))
#define exit(a, b) return cout << a, b;
#define eps (double)1e-9
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define vb vector<bool>
#define all(v) v.begin(), v.end()
#define ll long long
#define pii pair<int, int>
#define mii map<int, int>
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

const int N = (int)1e5 + 100;
int fac[N + 1], invfac[N + 1];
const int M = MOD;

int modexp(int a, int b) {
  if (b == 0)
    return 1;
  int ans = modexp(a, b / 2);
  ans = (ans * ans) % M;
  if (b % 2)
    ans = (ans * a) % M;
  return ans;
}

inline int inv(int a) { return modexp(a, M - 2); }

void prec() {
  fac[0] = 1;
  for (int i = 1; i <= N; i++)
    fac[i] = (fac[i - 1] * i) % M;
  invfac[N] = inv(fac[N]);
  for (int i = N - 1; i >= 0; i--)
    invfac[i] = (invfac[i + 1] * (i + 1)) % M;
}

int c(int n, int r) {
  int ans = fac[n];
  ans *= invfac[n - r], ans %= M;
  ans *= invfac[r], ans %= M;
  return ans;
}

signed main() {
  start_routine;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  prec();

  int n, m;
  cin >> n >> m;
  if (m == 1) {
    exit(1, 0);
  }

  int ret = 1;
  for (int i = 2;; i += 1) {
    int cnt = 0;
    while (m % i == 0) {
      cnt += 1;
      m /= i;
    }
    ret *= c(n + cnt - 1, cnt);
    ret %= M;
    if (m == 1) {
      exit(ret, 0);
    }
  }
  end_routine;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define init_random                                                            \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define start_routine                                                          \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  int begtime = clock();
#define end_routine                                                            \
  int endtime = clock();                                                       \
  cerr << endl                                                                 \
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC      \
       << " ms";                                                               \
  return 0
#define contests_de_diya_kar 0
#define PB push_back
#define MP make_pair
#define int long long
#define sd(n) scanf("%lld", &n)
#define pd(n) printf("%lld\n", n)
#define MOD ((long long)(1000 * 1000 * 1000 + 7))
#define exit(a, b) return cout << a, b;
#define eps (double)1e-9
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define vb vector<bool>
#define all(v) v.begin(), v.end()
#define ll long long
#define pii pair<int, int>
#define mii map<int, int>
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

const int N = (int)1e5 + 100;
int fac[N + 1], invfac[N + 1];
const int M = MOD;

int modexp(int a, int b) {
  if (b == 0)
    return 1;
  int ans = modexp(a, b / 2);
  ans = (ans * ans) % M;
  if (b % 2)
    ans = (ans * a) % M;
  return ans;
}

inline int inv(int a) { return modexp(a, M - 2); }

void prec() {
  fac[0] = 1;
  for (int i = 1; i <= N; i++)
    fac[i] = (fac[i - 1] * i) % M;
  invfac[N] = inv(fac[N]);
  for (int i = N - 1; i >= 0; i--)
    invfac[i] = (invfac[i + 1] * (i + 1)) % M;
}

int c(int n, int r) {
  int ans = fac[n];
  ans *= invfac[n - r], ans %= M;
  ans *= invfac[r], ans %= M;
  return ans;
}

signed main() {
  start_routine;
#ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
#endif
  prec();

  int n, m;
  cin >> n >> m;
  if (m == 1) {
    exit(1, 0);
  }

  int ret = 1;
  for (int i = 2;; i += 1) {
    int cnt = 0;
    while (m % i == 0) {
      cnt += 1;
      m /= i;
    }
    ret *= c(n + cnt - 1, cnt);
    ret %= M;
    if (m == 1) {
      exit(ret, 0);
    }
  }
  end_routine;
}