Problem p03213 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int N, n, ans;
map<int, int> x;
vector<int> w;
const int MOD = 1e9 + 7;
const int MAX = 100;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll comb(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 素因数分解
void prime_factor(int n) {
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      x[i]++;
      n /= i;
    }
  }
  if (n != 1)
    x[n]++;
}

void solve_25_3() {
  int n25 = 0, n3 = 0;
  for (int x : w) {
    if (3 <= x)
      n3++;
    if (25 <= x)
      n25++;
  }
  ans += n25 * (n3 - 1);
}

void solve_15_5() {
  int n15 = 0, n5 = 0;
  for (int x : w) {
    if (5 <= x)
      n5++;
    if (15 <= x)
      n15++;
  }
  ans += n15 * (n5 - 1);
}

void solve_5_5_3() {
  int n5 = 0, n3 = 0;
  for (int x : w) {
    if (5 <= x)
      n5++;
    if (3 <= x)
      n3++;
  }
  ans += comb(n5, 2) * (n3 - 2);
}

int main() {
  comb_init();
  cin >> N;
  for (int i = 1; i <= N; i++)
    prime_factor(i);
  for (auto p : x) {
    if (p.second > 1)
      w.push_back(p.second + 1);
  }
  n = w.size();
  ans = 0;
  if (75 <= w[0])
    ans++;
  solve_25_3();
  solve_15_5();
  solve_5_5_3();
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int N, n, ans;
map<int, int> x;
vector<int> w;
const int MOD = 1e9 + 7;
const int MAX = 100;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll comb(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 素因数分解
void prime_factor(int n) {
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      x[i]++;
      n /= i;
    }
  }
  if (n != 1)
    x[n]++;
}

void solve_25_3() {
  int n25 = 0, n3 = 0;
  for (int x : w) {
    if (3 <= x)
      n3++;
    if (25 <= x)
      n25++;
  }
  ans += n25 * (n3 - 1);
}

void solve_15_5() {
  int n15 = 0, n5 = 0;
  for (int x : w) {
    if (5 <= x)
      n5++;
    if (15 <= x)
      n15++;
  }
  ans += n15 * (n5 - 1);
}

void solve_5_5_3() {
  int n5 = 0, n3 = 0;
  for (int x : w) {
    if (5 <= x)
      n5++;
    if (3 <= x)
      n3++;
  }
  ans += comb(n5, 2) * (n3 - 2);
}

int main() {
  comb_init();
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++)
    prime_factor(i);
  for (auto p : x) {
    if (p.second > 1)
      w.push_back(p.second + 1);
  }
  n = w.size();
  ans = 0;
  if (75 <= w[0])
    ans++;
  solve_25_3();
  solve_15_5();
  solve_5_5_3();
  cout << ans << endl;
}