Problem p03253 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include "bits/stdc++.h"
#define rep(i, n) for (ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX c
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
// 階乗

long long modinv(long long a, long long m) { // modの逆元
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
ll Factrial(ll num) {
  if (num == 1 || num == 0) {
    return 1;
  } else if (num < 0) {
    printf("ERROR_minus\n");
    return 0;
  } else {
    return (num * Factrial(num - 1)) % d9_7;
  }
}

ll linercomb(ll n, ll k, ll mod) { // n,kの線形時間で求める
  ll ans = 1;
  for (ll i = n; i >= n - k + 1; i--) {
    ans *= i;
    ans %= mod;
  }
  ll k1 = Factrial(k);
  k1 %= mod;
  ans *= modinv(k1, mod);
  ans %= mod;
  return ans;
}
int main(void) {
  ll n, m;
  cin >> n >> m;
  ll now = 2;
  vi b(300000000, 0);
  set<ll> nums;
  if (m == 1) {
    cout << 1 << endl;
    return 0;
  }
  while (m != 1) {
    if (m % now == 0) {
      m /= now;
      b[now]++;
      nums.insert(now);
    } else {
      now += 1;
    }
  }
  ll ans = 1;
  for (auto i : nums) {
    // cout<<i<<" "<<b[i]<<endl;
    ans *= linercomb(n + (ll)b[i] - 1, (ll)b[i], d9_7);
    ans %= d9_7;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define rep(i, n) for (ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX c
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
// 階乗

long long modinv(long long a, long long m) { // modの逆元
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
ll Factrial(ll num) {
  if (num == 1 || num == 0) {
    return 1;
  } else if (num < 0) {
    printf("ERROR_minus\n");
    return 0;
  } else {
    return (num * Factrial(num - 1)) % d9_7;
  }
}

ll linercomb(ll n, ll k, ll mod) { // n,kの線形時間で求める
  ll ans = 1;
  for (ll i = n; i >= n - k + 1; i--) {
    ans *= i;
    ans %= mod;
  }
  ll k1 = Factrial(k);
  k1 %= mod;
  ans *= modinv(k1, mod);
  ans %= mod;
  return ans;
}
int main(void) {
  ll n, m;
  cin >> n >> m;
  ll now = 2;
  vi b(200000000, 0);
  set<ll> nums;
  if (m == 1) {
    cout << 1 << endl;
    return 0;
  }
  while (m != 1) {
    if (m % now == 0) {
      m /= now;
      b[now]++;
      nums.insert(now);
    } else {
      now += 1;
    }
  }
  ll ans = 1;
  for (auto i : nums) {
    // cout<<i<<" "<<b[i]<<endl;
    ans *= linercomb(n + (ll)b[i] - 1, (ll)b[i], d9_7);
    ans %= d9_7;
  }
  cout << ans << endl;
  return 0;
}