Problem p03253 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <set>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template <class T> void dump_array_impl(const T &a) {
  bool first = true;
  for (auto &&x : a) {
    if (!first) {
      cout << ", ";
      first = false;
    }
    cout << x;
  }
}
#define debug_array(a)                                                         \
  cout << (#a) << ": ";                                                        \
  dump_array_impl(a);                                                          \
  cout << endl
#else
#define debug(var)                                                             \
  {}
#define debug_array(a)                                                         \
  {}
#endif
template <class T> void read_n(vector<T> &v, size_t n) {
  v = vector<T>(n);
  for (lli i = 0; i < n; ++i)
    cin >> v[i];
}

vector<lli> factmem, factinvmem;
lli n, m, mod = 1e9 + 7;

lli fact(lli n) {
  if (factmem[n] == 0)
    factmem[n] = n * fact(n - 1) % mod;
  return factmem[n];
}

lli modinv(lli a) {
  lli b = mod, u = 1, v = 0;
  while (b) {
    lli t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

lli factinv(lli n) {
  if (factinvmem[n] == 0)
    factinvmem[n] = modinv(fact(n));
  return factinvmem[n];
}

lli conb(lli n, lli k) {
  return fact(n) * (factinv(k) * factinv(n - k) % mod) % mod;
}

int main() {
  factmem = vector<lli>(20000, 0);
  factinvmem = vector<lli>(20000, 0);
  factmem[0] = 1;

  cin >> n >> m;
  lli lim = sqrt((double)m);
  lli mm = m;
  lli ans = 1;
  for (lli i = 2; i <= lim; ++i) {
    lli cnt = 0;
    while (mm % i == 0) {
      mm /= i;
      ++cnt;
    }
    if (cnt > 0) {
      ans = ans * conb(cnt + n - 1, n - 1) % mod;
    }
  }
  if (mm > 1)
    ans = ans * conb(1 + n - 1, n - 1) % mod;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <set>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template <class T> void dump_array_impl(const T &a) {
  bool first = true;
  for (auto &&x : a) {
    if (!first) {
      cout << ", ";
      first = false;
    }
    cout << x;
  }
}
#define debug_array(a)                                                         \
  cout << (#a) << ": ";                                                        \
  dump_array_impl(a);                                                          \
  cout << endl
#else
#define debug(var)                                                             \
  {}
#define debug_array(a)                                                         \
  {}
#endif
template <class T> void read_n(vector<T> &v, size_t n) {
  v = vector<T>(n);
  for (lli i = 0; i < n; ++i)
    cin >> v[i];
}

vector<lli> factmem, factinvmem;
lli n, m, mod = 1e9 + 7;

lli fact(lli n) {
  if (factmem[n] == 0)
    factmem[n] = n * fact(n - 1) % mod;
  return factmem[n];
}

lli modinv(lli a) {
  lli b = mod, u = 1, v = 0;
  while (b) {
    lli t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

lli factinv(lli n) {
  if (factinvmem[n] == 0)
    factinvmem[n] = modinv(fact(n));
  return factinvmem[n];
}

lli conb(lli n, lli k) {
  return fact(n) * (factinv(k) * factinv(n - k) % mod) % mod;
}

int main() {
  factmem = vector<lli>(200000, 0);
  factinvmem = vector<lli>(200000, 0);
  factmem[0] = 1;

  cin >> n >> m;
  lli lim = sqrt((double)m);
  lli mm = m;
  lli ans = 1;
  for (lli i = 2; i <= lim; ++i) {
    lli cnt = 0;
    while (mm % i == 0) {
      mm /= i;
      ++cnt;
    }
    if (cnt > 0) {
      ans = ans * conb(cnt + n - 1, n - 1) % mod;
    }
  }
  if (mm > 1)
    ans = ans * conb(1 + n - 1, n - 1) % mod;
  cout << ans << endl;

  return 0;
}