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

/*===================*\\
|ID : harryPotter_421  |
|      LANG: C++       |
\\*====================*/
#include <bits/stdc++.h>
#include <iostream>
#define lli long long int
#define pb push_back
#define ld double
#define f(j, m, n) for (lli j = m; j < n; j++)
#define harry                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define forn(n)                                                                \\
  for (i = 0; i < n; i++)                                                      \\
    ;
using namespace std;
int prime[1000005];

void seive(lli n) // to generate all prime no less than or equal to n
{
  prime[0] = 0;
  prime[1] = 0;
  for (lli i = 2; i <= n; i++)
    prime[i] = 1;
  for (lli i = 2; i <= sqrt(n); i++) {
    if (prime[i]) {
      for (lli j = i * i; j <= n; j += i)
        prime[j] = 0;
    }
  }
}
vector<lli>
prime_factor(lli n) // Tp generate all prime factors of a given number n
{
  if (n == 1) {
    vector<lli> v;
    v.pb(1);
    return v;
  }
  if (prime[n]) {
    vector<lli> v;
    v.pb(1);
    v.pb(n);
    return v;
  } else {
    for (lli i = 2; i <= sqrt(n); i++) {
      if (prime[i] && n % i == 0) {

        vector<lli> vec = prime_factor(n / i);
        vec.pb(i);
        return vec;
      }
    }
  }
}

int main() {
  lli n;
  cin >> n;
  map<lli, lli> mp;
  lli sum = 0;

  while (n % 2 == 0) {
    mp[2]++;
    n = n / 2;
  }

  for (lli i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      mp[i]++;
      n = n / i;
    }
  }

  if (n > 2)
    mp[n]++;

  for (auto x : mp) {
    if (x.first != 1) {
      lli p = x.second;
      lli a = sqrt(1 + 8 * p);
      a--;
      a = a / 2;
      sum += (a);
    }
  }
  cout << sum;
}


Error: WA

Fixed submission:

/*===================*\\
|ID : harryPotter_421  |
|      LANG: C++       |
\\*====================*/
#include <bits/stdc++.h>
#include <iostream>
#define lli long long int
#define pb push_back
#define ld double
#define f(j, m, n) for (lli j = m; j < n; j++)
#define harry                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define forn(n)                                                                \\
  for (i = 0; i < n; i++)                                                      \\
    ;
using namespace std;
int prime[1000005];

void seive(lli n) // to generate all prime no less than or equal to n
{
  prime[0] = 0;
  prime[1] = 0;
  for (lli i = 2; i <= n; i++)
    prime[i] = 1;
  for (lli i = 2; i <= sqrt(n); i++) {
    if (prime[i]) {
      for (lli j = i * i; j <= n; j += i)
        prime[j] = 0;
    }
  }
}
vector<lli>
prime_factor(lli n) // Tp generate all prime factors of a given number n
{
  if (n == 1) {
    vector<lli> v;
    v.pb(1);
    return v;
  }
  if (prime[n]) {
    vector<lli> v;
    v.pb(1);
    v.pb(n);
    return v;
  } else {
    for (lli i = 2; i <= sqrt(n); i++) {
      if (prime[i] && n % i == 0) {

        vector<lli> vec = prime_factor(n / i);
        vec.pb(i);
        return vec;
      }
    }
  }
}

int main() {
  lli n;
  cin >> n;
  seive(1000001);
  vector<lli> v = prime_factor(n);
  map<lli, lli> mp;
  lli sum = 0;
  for (lli i = 0; i < v.size(); i++) {
    mp[v[i]]++;
  }
  for (auto x : mp) {
    if (x.first != 1) {
      lli p = x.second;
      lli a = sqrt(1 + 8 * p);
      a--;
      a = a / 2;
      sum += (a);
    }
  }
  cout << sum;
}