Problem p03253 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007; // 998244353; // 998244853;

template <typename T> struct modular {
  constexpr modular() : val(0) {}
  constexpr modular(const modular<T> &_m) : val(_m.val) {}
  template <typename U> constexpr modular(const U &_r = U()) {
    val = -MOD <= _r && _r < MOD ? _r : _r % MOD;
    if (val < 0) {
      val += MOD;
    }
  }
  const T operator()() { return val; }
  template <typename U> explicit operator U() const {
    return static_cast<U>(val);
  }
  modular<T> &operator+=(const modular<T> &_m) {
    if ((val += _m.val) >= MOD) {
      val -= MOD;
    }
    return *this;
  }
  modular<T> &operator-=(const modular<T> &_m) {
    if ((val -= _m.val) < 0) {
      val += MOD;
    }
    return *this;
  }
  modular<T> &operator*=(const modular<T> &_m) {
    val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val))
              .val;
    return *this;
  }
  modular<T> &operator/=(const modular<T> &_m) {
    T a = _m.val, b = MOD, u = 0, v = 1;
    while (a != 0) {
      T q = b / a;
      b -= q * a;
      swap(a, b);
      u -= q * v;
      swap(u, v);
    }
    return *this *= u;
  }
  modular<T> &operator=(const modular<T> &_m) {
    val = _m.val;
    return *this;
  }
  template <typename U> modular<T> &operator+=(const U &_r) {
    return *this += modular<T>(_r);
  }
  template <typename U> modular<T> &operator-=(const U &_r) {
    return *this -= modular<T>(_r);
  }
  template <typename U> modular<T> &operator*=(const U &_r) {
    return *this *= modular<T>(_r);
  }
  template <typename U> modular<T> &operator/=(const U &_r) {
    return *this /= modular<T>(_r);
  }
  template <typename U> modular<T> &operator=(const U &_r) {
    val = modular<T>(_r).val;
    return *this;
  }
  modular<T> operator-() { return modular<T>(-val); }
  template <typename U>
  friend bool operator==(const modular<U> &, const modular<U> &);
  friend std::istream &operator>>(std::istream &os, modular<T> &_m) {
    os >> _m.val;
    _m *= 1;
    return os;
  }
  friend std::ostream &operator<<(std::ostream &os, const modular<T> &_m) {
    return os << _m.val;
  }
  template <typename U> modular<T> exp(U e) {
    modular<T> res = 1;
    modular<T> b = val;
    if (e < 0) {
      b = 1 / b;
      e *= -1;
    }
    for (; e; e >>= 1) {
      if (e & 1) {
        res *= b;
      }
      b *= b;
    }
    return res;
  }

private:
  T val;
};
template <typename T>
inline modular<T> operator+(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) += _rhs;
}
template <typename T, typename U>
inline modular<T> operator+(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) += _rhs;
}
template <typename T, typename U>
inline modular<T> operator+(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) += _rhs;
}
template <typename T>
inline modular<T> operator-(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) -= _rhs;
}
template <typename T, typename U>
inline modular<T> operator-(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) -= _rhs;
}
template <typename T, typename U>
inline modular<T> operator-(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) -= _rhs;
}
template <typename T>
inline modular<T> operator*(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) *= _rhs;
}
template <typename T, typename U>
inline modular<T> operator*(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) *= _rhs;
}
template <typename T, typename U>
inline modular<T> operator*(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) *= _rhs;
}
template <typename T>
inline modular<T> operator/(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) /= _rhs;
}
template <typename T, typename U>
inline modular<T> operator/(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) /= _rhs;
}
template <typename T, typename U>
inline modular<T> operator/(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) /= _rhs;
}
template <typename T>
inline bool operator==(const modular<T> &_lhs, const modular<T> &_rhs) {
  return _lhs.val == _rhs.val;
}
template <typename T, typename U>
inline bool operator==(const modular<T> &_lhs, const U &_rhs) {
  return _lhs == modular<T>(_rhs);
}
template <typename T, typename U>
inline bool operator==(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) == _rhs;
}
template <typename T>
inline bool operator!=(const modular<T> &_lhs, const modular<T> &_rhs) {
  return !(_lhs == _rhs);
}
template <typename T, typename U>
inline bool operator!=(const modular<T> &_lhs, const U &_rhs) {
  return !(_lhs == _rhs);
}
template <typename T, typename U>
inline bool operator!=(const U &_lhs, const modular<T> &_rhs) {
  return !(_lhs == _rhs);
}
typedef modular<int> mint;

struct Comb {
  int N;
  vector<mint> fac, ifac, inv;

  Comb(int _n = 1) {
    resize(2);
    fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
    N = 1;
    grow(_n);
  }

  void resize(int _s) {
    fac.resize(_s);
    ifac.resize(_s);
    inv.resize(_s);
  }
  bool grow(int _n) {
    if (_n <= N)
      return false;
    swap(_n, N);
    resize(N + 1);
    for (int i = _n + 1; i <= N; i++) {
      fac[i] = fac[i - 1] * i;
      inv[i] = (-MOD / i) * inv[MOD % i];
      ifac[i] = ifac[i - 1] * inv[i];
    }
    return true;
  }
  // perm
  mint a(int n, int k) {
    if (n < k || k < 0)
      return 0;
    if (n > N)
      grow(n);
    return fac[n] * ifac[n - k];
  }
  // choose
  mint c(int n, int k) {
    if (n < k || k < 0)
      return 0;
    if (n > N)
      grow(n);
    return fac[n] * ifac[n - k] * ifac[k];
  }
  // sum x = s, x > 0
  mint p(int s, int k) { return c(s - 1, k - 1); }
  // sum x = s, x >= 0
  mint z(int s, int k) { return p(s + k, k); }
  // \E Y-X >= m
  mint hit(int n, int k, int m = 1) {
    if (m <= k - n)
      return c(n + k, n);
    return c(n + k, k - m);
  }
  // catalan trapezoids C_m(n, k)
  // \A Y-X < m,  =c(n+k,n) - hit
  mint cat(int n, int k, int m = 1) {
    if (m > k)
      return c(n + k, n);
    if (m <= k - n)
      return 0;
    return c(n + k, n) - c(n + k, k - m);
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> prime;
  auto sieve = [&](int _n = 45000) {
    vector<bool> is(_n + 1, true);
    is[0] = is[1] = false;
    for (int p = 2; p * p <= _n; p++) {
      if (is[p]) {
        for (int i = p * p; i <= _n; i += p) {
          is[i] = false;
        }
      }
    }
    for (int i = 2; i <= _n; i++) {
      if (is[i])
        prime.emplace_back(i);
    }
  };
  auto decomp = [&](int x) {
    assert(x > 1);
    vector<pair<int, int>> res;
    for (int p : prime) {
      if (p * p > x)
        break;
      if (x % p == 0) {
        int e = 0;
        while (x % p == 0) {
          e++;
          x /= p;
        }
        res.emplace_back(p, e);
      }
    }
    if (x != 1)
      res.emplace_back(x, 1);
    return res;
  };
  sieve();
  Comb c(n);
  mint res = 1;
  for (auto &p : decomp(m)) {
    int e = p.second;
    res *= c.z(e, n);
  }
  cout << res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007; // 998244353; // 998244853;

template <typename T> struct modular {
  constexpr modular() : val(0) {}
  constexpr modular(const modular<T> &_m) : val(_m.val) {}
  template <typename U> constexpr modular(const U &_r = U()) {
    val = -MOD <= _r && _r < MOD ? _r : _r % MOD;
    if (val < 0) {
      val += MOD;
    }
  }
  const T operator()() { return val; }
  template <typename U> explicit operator U() const {
    return static_cast<U>(val);
  }
  modular<T> &operator+=(const modular<T> &_m) {
    if ((val += _m.val) >= MOD) {
      val -= MOD;
    }
    return *this;
  }
  modular<T> &operator-=(const modular<T> &_m) {
    if ((val -= _m.val) < 0) {
      val += MOD;
    }
    return *this;
  }
  modular<T> &operator*=(const modular<T> &_m) {
    val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val))
              .val;
    return *this;
  }
  modular<T> &operator/=(const modular<T> &_m) {
    T a = _m.val, b = MOD, u = 0, v = 1;
    while (a != 0) {
      T q = b / a;
      b -= q * a;
      swap(a, b);
      u -= q * v;
      swap(u, v);
    }
    return *this *= u;
  }
  modular<T> &operator=(const modular<T> &_m) {
    val = _m.val;
    return *this;
  }
  template <typename U> modular<T> &operator+=(const U &_r) {
    return *this += modular<T>(_r);
  }
  template <typename U> modular<T> &operator-=(const U &_r) {
    return *this -= modular<T>(_r);
  }
  template <typename U> modular<T> &operator*=(const U &_r) {
    return *this *= modular<T>(_r);
  }
  template <typename U> modular<T> &operator/=(const U &_r) {
    return *this /= modular<T>(_r);
  }
  template <typename U> modular<T> &operator=(const U &_r) {
    val = modular<T>(_r).val;
    return *this;
  }
  modular<T> operator-() { return modular<T>(-val); }
  template <typename U>
  friend bool operator==(const modular<U> &, const modular<U> &);
  friend std::istream &operator>>(std::istream &os, modular<T> &_m) {
    os >> _m.val;
    _m *= 1;
    return os;
  }
  friend std::ostream &operator<<(std::ostream &os, const modular<T> &_m) {
    return os << _m.val;
  }
  template <typename U> modular<T> exp(U e) {
    modular<T> res = 1;
    modular<T> b = val;
    if (e < 0) {
      b = 1 / b;
      e *= -1;
    }
    for (; e; e >>= 1) {
      if (e & 1) {
        res *= b;
      }
      b *= b;
    }
    return res;
  }

private:
  T val;
};
template <typename T>
inline modular<T> operator+(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) += _rhs;
}
template <typename T, typename U>
inline modular<T> operator+(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) += _rhs;
}
template <typename T, typename U>
inline modular<T> operator+(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) += _rhs;
}
template <typename T>
inline modular<T> operator-(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) -= _rhs;
}
template <typename T, typename U>
inline modular<T> operator-(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) -= _rhs;
}
template <typename T, typename U>
inline modular<T> operator-(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) -= _rhs;
}
template <typename T>
inline modular<T> operator*(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) *= _rhs;
}
template <typename T, typename U>
inline modular<T> operator*(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) *= _rhs;
}
template <typename T, typename U>
inline modular<T> operator*(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) *= _rhs;
}
template <typename T>
inline modular<T> operator/(const modular<T> &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) /= _rhs;
}
template <typename T, typename U>
inline modular<T> operator/(const modular<T> &_lhs, const U &_rhs) {
  return modular<T>(_lhs) /= _rhs;
}
template <typename T, typename U>
inline modular<T> operator/(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) /= _rhs;
}
template <typename T>
inline bool operator==(const modular<T> &_lhs, const modular<T> &_rhs) {
  return _lhs.val == _rhs.val;
}
template <typename T, typename U>
inline bool operator==(const modular<T> &_lhs, const U &_rhs) {
  return _lhs == modular<T>(_rhs);
}
template <typename T, typename U>
inline bool operator==(const U &_lhs, const modular<T> &_rhs) {
  return modular<T>(_lhs) == _rhs;
}
template <typename T>
inline bool operator!=(const modular<T> &_lhs, const modular<T> &_rhs) {
  return !(_lhs == _rhs);
}
template <typename T, typename U>
inline bool operator!=(const modular<T> &_lhs, const U &_rhs) {
  return !(_lhs == _rhs);
}
template <typename T, typename U>
inline bool operator!=(const U &_lhs, const modular<T> &_rhs) {
  return !(_lhs == _rhs);
}
typedef modular<int> mint;

struct Comb {
  int N;
  vector<mint> fac, ifac, inv;

  Comb(int _n = 1) {
    resize(2);
    fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
    N = 1;
    grow(_n);
  }

  void resize(int _s) {
    fac.resize(_s);
    ifac.resize(_s);
    inv.resize(_s);
  }
  bool grow(int _n) {
    if (_n <= N)
      return false;
    swap(_n, N);
    resize(N + 1);
    for (int i = _n + 1; i <= N; i++) {
      fac[i] = fac[i - 1] * i;
      inv[i] = (-MOD / i) * inv[MOD % i];
      ifac[i] = ifac[i - 1] * inv[i];
    }
    return true;
  }
  // perm
  mint a(int n, int k) {
    if (n < k || k < 0)
      return 0;
    if (n > N)
      grow(n);
    return fac[n] * ifac[n - k];
  }
  // choose
  mint c(int n, int k) {
    if (n < k || k < 0)
      return 0;
    if (n > N)
      grow(n);
    return fac[n] * ifac[n - k] * ifac[k];
  }
  // sum x = s, x > 0
  mint p(int s, int k) { return c(s - 1, k - 1); }
  // sum x = s, x >= 0
  mint z(int s, int k) { return p(s + k, k); }
  // \E Y-X >= m
  mint hit(int n, int k, int m = 1) {
    if (m <= k - n)
      return c(n + k, n);
    return c(n + k, k - m);
  }
  // catalan trapezoids C_m(n, k)
  // \A Y-X < m,  =c(n+k,n) - hit
  mint cat(int n, int k, int m = 1) {
    if (m > k)
      return c(n + k, n);
    if (m <= k - n)
      return 0;
    return c(n + k, n) - c(n + k, k - m);
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  if (m == 1) {
    cout << 1;
    return;
  }
  vector<int> prime;
  auto sieve = [&](int _n = 45000) {
    vector<bool> is(_n + 1, true);
    is[0] = is[1] = false;
    for (int p = 2; p * p <= _n; p++) {
      if (is[p]) {
        for (int i = p * p; i <= _n; i += p) {
          is[i] = false;
        }
      }
    }
    for (int i = 2; i <= _n; i++) {
      if (is[i])
        prime.emplace_back(i);
    }
  };
  auto decomp = [&](int x) {
    assert(x > 1);
    vector<pair<int, int>> res;
    for (int p : prime) {
      if (p * p > x)
        break;
      if (x % p == 0) {
        int e = 0;
        while (x % p == 0) {
          e++;
          x /= p;
        }
        res.emplace_back(p, e);
      }
    }
    if (x != 1)
      res.emplace_back(x, 1);
    return res;
  };
  sieve();
  Comb c(n);
  mint res = 1;
  for (auto &p : decomp(m)) {
    int e = p.second;
    res *= c.z(e, n);
  }
  cout << res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}