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

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

#define Fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define fWrite freopen("out.txt", "w", stdout);
#define TC                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  FOR(tc, 1, t)
#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define MEM(a, x) memset(a, x, sizeof(a))
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, b) for (int i = 0; i < b; i++)

const int NUM = 2000005;
bool flag[NUM];
vector<LL> prime;
void sieve() {
  flag[1] = true;
  for (LL i = 4; i < NUM; i += 2)
    flag[i] = true;
  for (LL i = 3; i * i <= NUM; i += 2) {
    if (!flag[i]) {
      for (LL j = i * i; j < NUM; j += (i << 1))
        flag[j] = true;
    }
  }
  prime.pb(2);
  for (LL i = 3; i < NUM; i += 2)
    if (!flag[i])
      prime.pb(i);
  return;
}

map<LL, LL> mp;
void NOD(LL n) {
  for (LL i = 0; prime[i] * prime[i] <= n; i++) {
    if (n % prime[i] == 0) {
      LL cnt = 0;
      while (n % prime[i] == 0) {
        n /= prime[i];
        cnt++;
      }
      mp[prime[i]] = cnt;
    }
  }
  if (n > 1) {
    mp[n] = 1;
  }
  return;
}

int main() {
  sieve();
  LL n;
  cin >> n;
  NOD(n);
  LL cnt = 0;
  for (auto p : mp) {
    LL x = p.ss;
    LL r = 1;
    while (x >= r) {
      x -= r;
      r++;
      cnt++;
    }
  }
  cout << cnt;
}


Error: WA

Fixed submission:

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

#define Fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define fWrite freopen("out.txt", "w", stdout);
#define TC                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  FOR(tc, 1, t)
#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define MEM(a, x) memset(a, x, sizeof(a))
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, b) for (int i = 0; i < b; i++)

const int NUM = 1000005;
bool flag[NUM];
vector<int> prime;
void sieve() {
  flag[1] = true;
  for (int i = 4; i < NUM; i += 2)
    flag[i] = true;
  for (int i = 3; i * i <= NUM; i += 2) {
    if (!flag[i]) {
      for (int j = i * i; j < NUM; j += (i << 1))
        flag[j] = true;
    }
  }
  prime.pb(2);
  for (int i = 3; i < NUM; i += 2)
    if (!flag[i])
      prime.pb(i);
  return;
}

map<LL, int> mp;
void NOD(LL n) {
  for (int i = 0; prime[i] * prime[i] <= n; i++) {
    if (n % prime[i] == 0) {
      int cnt = 0;
      while (n % prime[i] == 0) {
        n /= prime[i];
        cnt++;
      }
      mp[prime[i]] = cnt;
    }
  }
  if (n > 1) {
    mp[n] = 1;
  }
  return;
}

int main() {
  sieve();
  LL n;
  cin >> n;
  NOD(n);
  int cnt = 0;
  for (auto p : mp) {
    int x = p.ss;
    int r = 1;
    while (x >= r) {
      x -= r;
      r++;
      cnt++;
    }
  }
  cout << cnt;
}