Problem p03253 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vi = vector<int>;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// int dp[100100][100100];

ll power(int m, int n) { // m^n（繰り返し自乗法）
  if (n == 0)
    return 1;
  if (n % 2 == 1)
    return power(m, n - 1) * m % mod;
  ll r = power(m, n / 2);
  return r * r % mod;
}

// ll fact(int n) { // 階乗
//     return f[n];
// }

ll inv(ll a, ll b) { // 逆元を利用してa/bのmodを返す
  return a * power(b, mod - 2) % mod;
}

ll f[101000];

ll comb(int n, int r) { // nCr
  if (n < r)
    return 0;
  // if (n == r || r == 0) return dp[n][r] = 1;
  // if (r == 1) return dp[n][r] = n;
  // if (dp[n][r] != 0) return dp[n][r];
  // return dp[n][r] = (comb(n-1, r-1) + comb(n-1, r)) % mod;
  if (n == r || r == 0)
    return 1;
  ll s = f[n - r] * f[r] % mod;
  return inv(f[n], s);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll p = 1;
  rep(i, 101000) {
    if (i == 0)
      f[i] = 1;
    else {
      p *= i;
      p %= mod;
      f[i] = p;
    }
  }
  int n, m;
  cin >> n >> m;
  int M = m;
  ll r = 1;
  for (int i = 2; i <= m; i++) {
    int cnt = 0;
    if (M % i == 0) {
      while (M % i == 0) {
        M /= i;
        cnt++;
      }
      // cout << cnt << "\n";
      r *= comb(cnt + n - 1, cnt);
      r %= mod;
    }
  }
  cout << r << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vi = vector<int>;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// int dp[100100][100100];

ll power(int m, int n) { // m^n（繰り返し自乗法）
  if (n == 0)
    return 1;
  if (n % 2 == 1)
    return power(m, n - 1) * m % mod;
  ll r = power(m, n / 2);
  return r * r % mod;
}

// ll fact(int n) { // 階乗
//     return f[n];
// }

ll inv(ll a, ll b) { // 逆元を利用してa/bのmodを返す
  return a * power(b, mod - 2) % mod;
}

ll f[101000];

ll comb(int n, int r) { // nCr
  if (n < r)
    return 0;
  // if (n == r || r == 0) return dp[n][r] = 1;
  // if (r == 1) return dp[n][r] = n;
  // if (dp[n][r] != 0) return dp[n][r];
  // return dp[n][r] = (comb(n-1, r-1) + comb(n-1, r)) % mod;
  if (n == r || r == 0)
    return 1;
  ll s = f[n - r] * f[r] % mod;
  return inv(f[n], s);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll p = 1;
  rep(i, 101000) {
    if (i == 0)
      f[i] = 1;
    else {
      p *= i;
      p %= mod;
      f[i] = p;
    }
  }
  int n, m;
  cin >> n >> m;
  int M = m;
  ll r = 1;
  for (int i = 2; i <= M; i++) {
    int cnt = 0;
    if (M % i == 0) {
      while (M % i == 0) {
        M /= i;
        cnt++;
      }
      // cout << cnt << "\n";
      r *= comb(cnt + n - 1, cnt);
      r %= mod;
    }
  }
  cout << r << "\n";
}