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

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define PER(i, n) for (ll i = n; i >= 1; i--)
#define sz(x) ll(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\\n" : "No\\n")
#define endl '\\n'
#define fi first
#define se second
using ll = long long;
using P = pair<ll, ll>;
using Pl = pair<ll, ll>;
using vi = vector<ll>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const ll dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const ll dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 62) - 1;
ll ceil(const ll &a, const ll &b) { return ((a) + (b)-1) / b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

struct Sieve { // 篩
  ll n;
  vector<ll> f, primes;
  Sieve(ll n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(ll x) { return f[x] == x; } // 素数判定
  vector<ll> factorList(ll x) {            // 素因数列挙
    vector<ll> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(ll x) { // 素因数分解(ランレングス圧縮的なもの)
    vector<ll> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (ll p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  cin >> n;
  ll m = 0;
  while (m * m < n)
    m++;
  Sieve s(m);
  s.primes.push_back(n);
  ll idx = 0;
  map<ll, ll> mp;
  while (n > 1 && idx < sz(s.primes)) {
    if (n % s.primes[idx] == 0) {
      mp[s.primes[idx]]++;
      n /= s.primes[idx];
    } else
      idx++;
  }
  if (n != 1)
    mp[n]++;
  ll ans = 0;
  for (Pl p : mp) {
    ll cnt = 0;
    ll cur = 1;
    while (cnt + cur <= p.se) {
      cnt += cur;
      cur++;
      ans++;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define PER(i, n) for (ll i = n; i >= 1; i--)
#define sz(x) ll(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\\n" : "No\\n")
#define endl '\\n'
#define fi first
#define se second
using ll = long long;
using P = pair<ll, ll>;
using Pl = pair<ll, ll>;
using vi = vector<ll>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const ll dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const ll dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 62) - 1;
ll ceil(const ll &a, const ll &b) { return ((a) + (b)-1) / b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

struct Sieve { // 篩
  ll n;
  vector<ll> f, primes;
  Sieve(ll n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(ll x) { return f[x] == x; } // 素数判定
  vector<ll> factorList(ll x) {            // 素因数列挙
    vector<ll> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(ll x) { // 素因数分解(ランレングス圧縮的なもの)
    vector<ll> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (ll p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  cin >> n;
  ll m = 0;
  while (m * m < n)
    m++;
  Sieve s(m);
  s.primes.push_back(n);
  ll idx = 0;
  map<ll, ll> mp;
  while (n > 1) {
    if (n % s.primes[idx] == 0) {
      mp[s.primes[idx]]++;
      n /= s.primes[idx];
    } else
      idx++;
  }
  ll ans = 0;
  for (Pl p : mp) {
    ll cnt = 0;
    ll cur = 1;
    while (cnt + cur <= p.se) {
      cnt += cur;
      cur++;
      ans++;
    }
  }
  cout << ans << endl;
}