Problem p03253 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int mod = 1e9 + 7;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { return (a.n += b.n) >= mod ? a.n - mod : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + mod : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % mod; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

mint dp[100][500];

mint fact[200000];
mint ifact[200000];
mint inv[200000];

int main() {
  inv[1] = 1;
  for (int i = 2; i < 200000; i++) {
    inv[i] = inv[mod % i] * (mod - mod / i);
  }
  fact[0] = 1;
  ifact[0] = 1;
  for (int i = 1; i < 200000; i++) {
    fact[i] = i * fact[i - 1];
    ifact[i] = inv[i] * ifact[i - 1];
  }
  int n, m;
  cin >> n >> m;
  vector<int> divs;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      divs.push_back(i);
      if (m / i != i)
        divs.push_back(m / i);
    }
  }
  sort(divs.begin(), divs.end());
  const int N = divs.size();
  dp[0][N - 1] = 1;
  for (int i = 0; i < 99; i++) {
    for (int j = 1; j < N; j++) {
      for (int k = 1; k < N; k++) {
        if (divs[j] % divs[k] != 0)
          continue;
        int nn = divs[j] / divs[k];
        int l = lower_bound(divs.begin(), divs.end(), nn) - divs.begin();
        dp[i + 1][l] += dp[i][j];
      }
    }
  }
  mint ans;
  for (int i = 0; i <= min(99, n); i++) {
    ans += dp[i][0] * fact[n] * ifact[i] * ifact[n - i];
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int mod = 1e9 + 7;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { return (a.n += b.n) >= mod ? a.n - mod : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + mod : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % mod; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

mint dp[100][1400];

mint fact[200000];
mint ifact[200000];
mint inv[200000];

int main() {
  inv[1] = 1;
  for (int i = 2; i < 200000; i++) {
    inv[i] = inv[mod % i] * (mod - mod / i);
  }
  fact[0] = 1;
  ifact[0] = 1;
  for (int i = 1; i < 200000; i++) {
    fact[i] = i * fact[i - 1];
    ifact[i] = inv[i] * ifact[i - 1];
  }
  int n, m;
  cin >> n >> m;
  vector<int> divs;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      divs.push_back(i);
      if (m / i != i)
        divs.push_back(m / i);
    }
  }
  sort(divs.begin(), divs.end());
  const int N = divs.size();
  dp[0][N - 1] = 1;
  for (int i = 0; i < 99; i++) {
    for (int j = 1; j < N; j++) {
      for (int k = 1; k < N; k++) {
        if (divs[j] % divs[k] != 0)
          continue;
        int nn = divs[j] / divs[k];
        int l = lower_bound(divs.begin(), divs.end(), nn) - divs.begin();
        dp[i + 1][l] += dp[i][j];
      }
    }
  }
  mint ans;
  for (int i = 0; i <= min(99, n); i++) {
    ans += dp[i][0] * fact[n] * ifact[i] * ifact[n - i];
  }
  cout << ans << endl;
}