Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define st first
#define nd second
#define endl '\\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x)                                                           \\
  cerr << #x << " is ";                                                        \\
  for (auto &e : (x))                                                          \\
    cerr << e << ' ';                                                          \\
  cerr << '\\n'; // vector, set
#define what_is_a(x, n)                                                        \\
  cerr << #x << " is ";                                                        \\
  for (int i = 0; i < n; i++)                                                  \\
    cerr << x[i] << ' ';                                                       \\
  cerr << '\\n'; // n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x)                                                          \\
  cerr << #x << " is ";                                                        \\
  for (auto &e : (x))                                                          \\
    cerr << cerr_pair(e) << ' ';                                               \\
  cerr << '\\n'; // vector, set
#define pwhat_is_a(x, n)                                                       \\
  cerr << #x << " is ";                                                        \\
  for (int i = 0; i < n; i++)                                                  \\
    cerr << cerr_pair(x[i]) << ' ';                                            \\
  cerr << '\\n'; // n first element of array
#define int long long
// #define pow mypow

typedef pair<int, int> pii;
const int N = 1e6 + 5;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int n;

int32_t main() {
  IOS
          // freopen("input.txt", "r", stdin);
          cin >>
      n;
  int ans = 0;
  for (int i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    int num = 1;
    while (num <= cnt) {
      cnt -= num;
      num++;
      ans++;
    }
  }
  if (n > 1)
    ans++;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define st first
#define nd second
#define endl '\\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x)                                                           \\
  cerr << #x << " is ";                                                        \\
  for (auto &e : (x))                                                          \\
    cerr << e << ' ';                                                          \\
  cerr << '\\n'; // vector, set
#define what_is_a(x, n)                                                        \\
  cerr << #x << " is ";                                                        \\
  for (int i = 0; i < n; i++)                                                  \\
    cerr << x[i] << ' ';                                                       \\
  cerr << '\\n'; // n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x)                                                          \\
  cerr << #x << " is ";                                                        \\
  for (auto &e : (x))                                                          \\
    cerr << cerr_pair(e) << ' ';                                               \\
  cerr << '\\n'; // vector, set
#define pwhat_is_a(x, n)                                                       \\
  cerr << #x << " is ";                                                        \\
  for (int i = 0; i < n; i++)                                                  \\
    cerr << cerr_pair(x[i]) << ' ';                                            \\
  cerr << '\\n'; // n first element of array
#define int long long
// #define pow mypow

typedef pair<int, int> pii;
const int N = 1e6 + 5;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

bool is_prime(int x) { // x>=2
  if (x < 2)
    return 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0)
      return false;
  }
  return true;
}
int n;
int solve(int m) {
  int res = 1;
  while (res * (res + 1) <= 2 * m)
    res++;
  return res - 1;
}
int32_t main() {
  IOS
          // freopen("input.txt", "r", stdin);
          cin >>
      n;
  if (n == 1)
    return 0 * puts("0");
  if (is_prime(n))
    return 0 * puts("1");
  set<int> divisors;
  vector<int> cnt(N, 0);
  for (int i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    while (n % i == 0) {
      divisors.insert(i);
      cnt[i]++;
      n /= i;
    }
  }
  if (is_prime(n)) {
    divisors.insert(n);
    cnt[n]++;
  }
  int ans = 0;
  for (int d : divisors)
    ans += solve(cnt[d]);
  cout << ans << endl;
  return 0;
}