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

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

#define DEBUG

typedef long long int ll;
typedef long double ld;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int>>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for (ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for (ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a)                                                              \\
  t a;                                                                         \\
  cin >> a;
#define rd2(t, a, b)                                                           \\
  rd1(t, a);                                                                   \\
  rd1(t, b);
#define rd3(t, a, b, c)                                                        \\
  rd2(t, a, b);                                                                \\
  rd1(t, c);
#define rd4(t, a, b, c, d)                                                     \\
  rd3(t, a, b, c);                                                             \\
  rd1(t, d);
#define rd5(t, a, b, c, d, e)                                                  \\
  rd4(t, a, b, c, d);                                                          \\
  rd1(t, e);
#define rd6(t, a, b, c, d, e, f)                                               \\
  rd5(t, a, b, c, d, e);                                                       \\
  rd1(t, f);
#define rdA(t, nm, len)                                                        \\
  t nm[len];                                                                   \\
  loop(i, len) { cin >> nm[i]; }
#ifdef DEBUG
#define deb(v) cout << endl << #v << ": " << v << endl
#define db1(v)                                                                 \\
  cout << endl                                                                 \\
       << #v << ": "                                                           \\
       << "[ ";                                                                \\
  for (auto x : v) {                                                           \\
    cout << x << " ";                                                          \\
  };                                                                           \\
  cout << "]" << endl;
#define db2(v)                                                                 \\
  cout << endl << #v << ": " << endl;                                          \\
  for (auto r : v) {                                                           \\
    cout << "[ ";                                                              \\
    for (auto x : r) {                                                         \\
      cout << x << " ";                                                        \\
    };                                                                         \\
    cout << "]" << endl;                                                       \\
  };
#define dbl cout << "-------------------------------" << endl
#else
#define deb(v)
#define db1(v)
#define db2(v)
#define dbl
#endif

ll cav(ll q) {
  ll cl = (-1 + sqrt(1 + 8 * q)) / 2;

  return cl;
}

void SieveOfEratosthenes(int n, vl &pms) {
  ll on = n;
  //    n = sqrt(n);
  bool prime[n + 1];
  //    vector<bool> prime(n + 1, );
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= on; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= on; i += p)
        prime[i] = false;
    }
  }

  for (int p = 2; p <= n; p++)
    if (prime[p])
      pms.pb(p);
}

void solve() {
  rd1(ll, n);
  ll on = n;
  map<ll, ll> m;
  vl pms;
  SieveOfEratosthenes(1001111, pms);
  ll tp = n;
  for (auto x : pms) {
    if (n % x == 0) {
      ll ct = 0;
      while (n % x == 0) {
        ct++;
        n = n / x;
      }
      m[x] = ct;
    }
  }
  if (n > 2) {
    m[on] = 1;
  }

  int ans = 0;
  for (auto x : m) {
    ll prime = x.F, pwr = x.S;
    ans += cav(pwr);
  }

  cout << ans;
}

int main() {

  fastio;

  //	rd1(ll, t);
  ll t = 1;

  while (t--) {
    //        deb(t);
    solve();
  }

  return 0;
}

Error: WA

Fixed submission:

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

#define DEBUG

typedef long long int ll;
typedef long double ld;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int>>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for (ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for (ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a)                                                              \\
  t a;                                                                         \\
  cin >> a;
#define rd2(t, a, b)                                                           \\
  rd1(t, a);                                                                   \\
  rd1(t, b);
#define rd3(t, a, b, c)                                                        \\
  rd2(t, a, b);                                                                \\
  rd1(t, c);
#define rd4(t, a, b, c, d)                                                     \\
  rd3(t, a, b, c);                                                             \\
  rd1(t, d);
#define rd5(t, a, b, c, d, e)                                                  \\
  rd4(t, a, b, c, d);                                                          \\
  rd1(t, e);
#define rd6(t, a, b, c, d, e, f)                                               \\
  rd5(t, a, b, c, d, e);                                                       \\
  rd1(t, f);
#define rdA(t, nm, len)                                                        \\
  t nm[len];                                                                   \\
  loop(i, len) { cin >> nm[i]; }
#ifdef DEBUG
#define deb(v) cout << endl << #v << ": " << v << endl
#define db1(v)                                                                 \\
  cout << endl                                                                 \\
       << #v << ": "                                                           \\
       << "[ ";                                                                \\
  for (auto x : v) {                                                           \\
    cout << x << " ";                                                          \\
  };                                                                           \\
  cout << "]" << endl;
#define db2(v)                                                                 \\
  cout << endl << #v << ": " << endl;                                          \\
  for (auto r : v) {                                                           \\
    cout << "[ ";                                                              \\
    for (auto x : r) {                                                         \\
      cout << x << " ";                                                        \\
    };                                                                         \\
    cout << "]" << endl;                                                       \\
  };
#define dbl cout << "-------------------------------" << endl
#else
#define deb(v)
#define db1(v)
#define db2(v)
#define dbl
#endif

ll cav(ll q) {
  ll cl = (-1 + sqrt(1 + 8 * q)) / 2;

  return cl;
}

void SieveOfEratosthenes(int n, vl &pms) {
  ll on = n;
  n = sqrt(n);
  bool prime[n + 1];
  //    vector<bool> prime(n + 1, );
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= on; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (int p = 2; p <= n; p++)
    if (prime[p])
      pms.pb(p);
}

void solve() {
  rd1(ll, n);
  ll on = n;
  map<ll, ll> m;
  vl pms;
  SieveOfEratosthenes(n, pms);
  ll tp = n;
  for (auto x : pms) {
    if (n % x == 0) {
      ll ct = 0;
      while (n % x == 0) {
        ct++;
        n = n / x;
      }
      m[x] = ct;
    }
  }
  if (n > 2) {
    m[on] = 1;
  }

  int ans = 0;
  for (auto x : m) {
    ll prime = x.F, pwr = x.S;
    ans += cav(pwr);
  }

  cout << ans;
}

int main() {

  fastio;

  //	rd1(ll, t);
  ll t = 1;

  while (t--) {
    //        deb(t);
    solve();
  }

  return 0;
}