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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
typedef long double ld;
using namespace std;

vector<ll> sieve(ll n) {
  vector<ll> a(n + 1, 0);
  for (ll i = 3; i <= n; i += 2)
    a[i] = 1;
  for (ll i = 3; i <= n; i += 2) {
    if (a[i] == 1) {
      for (ll j = i * 2; j <= n; j += i)
        a[j] = 0;
    }
  }
  a[2] = 1;
  a[1] = a[0] = 0;
  return a;
}
ll reverse(ll n) {
  ll s = 0;
  while (n > 0) {
    ll t = n % 10;
    s = s * 10 + t;
    n /= 10;
  }
  return s;
}
int count_setbits(int N)

{
  int cnt = 0;

  while (N > 0)

  {

    cnt += (N & 1);

    N = N >> 1;
  }

  return cnt;
}
ll power(ll x, ll y) {
  int res = 1; // Initialize result

  x = x % mod; // Update x if it is more than or
               // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % mod;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % mod;
  }
  return res;
}

void BellmanFord(vector<vector<ll>> &graph, int V, int E, int src) {
  // Initialize distance of all vertices as infinite.
  int dis[V];
  for (int i = 0; i < V; i++)
    dis[i] = INT_MAX;

  // initialize distance of source as 0
  dis[src] = 0;

  // Relax all edges |V| - 1 times. A simple
  // shortest path from src to any other
  // vertex can have at-most |V| - 1 edges
  for (int i = 0; i < V - 1; i++) {

    for (int j = 0; j < E; j++) {
      if (dis[graph[j][0]] + graph[j][2] < dis[graph[j][1]])
        dis[graph[j][1]] = dis[graph[j][0]] + graph[j][2];
    }
  }

  // check for negative-weight cycles.
  // The above step guarantees shortest
  // distances if graph doesn't contain
  // negative weight cycle.  If we get a
  // shorter path, then there is a cycle.
  for (int i = 0; i < E; i++) {
    int x = graph[i][0];
    int y = graph[i][1];
    int weight = graph[i][2];
    if (dis[x] != INT_MAX && dis[x] + weight < dis[y])
      cout << "Graph contains negative"
              " weight cycle"
           << endl;
  }
}
int main() {
  ull n;
  cin >> n;
  unordered_map<ull, ull> mp;
  while (n % 2 == 0) {
    mp[2]++;
    n /= 2;
  }
  for (ull i = 3; i <= sqrt(n); i = i + 2) {
    // While i divides n, print i and divide n
    while (n % i == 0) {
      mp[i]++;
      n = n / i;
    }
  }
  if (n > 2)
    mp[n]++;
  /* for(auto i:mp)
   cout<<i.first<<" "<<i.second<<"\\n";*/
  ull res = 0;

  for (auto j : mp) {
    ull i = 1;
    while ((i * (i + 1) / 2) <= j.second) {
      i++;
    }
    i--;
    res += i;
  }
  cout << res << "\\n";
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
typedef long double ld;
using namespace std;

vector<ll> primeFactorize(ll n) {
  vector<ll> spf(n + 1);
  spf[1] = 1;
  for (ll i = 2; i <= n; i++)

    spf[i] = i;
  for (ll i = 4; i <= n; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i <= n; i++) {
    if (spf[i] == i) {

      for (ll j = i * i; j <= n; j += i)

        if (spf[j] == j)
          spf[j] = i;
    }
  }
  vector<ll> ret;
  while (n != 1) {
    ret.push_back(spf[n]);
    n = n / spf[n];
  }
  return ret;
}

vector<ll> sieve(ll n) {
  vector<ll> a(n + 1, 0);
  for (ll i = 3; i <= n; i += 2)
    a[i] = 1;
  for (ll i = 3; i <= n; i += 2) {
    if (a[i] == 1) {
      for (ll j = i * 2; j <= n; j += i)
        a[j] = 0;
    }
  }
  a[2] = 1;
  a[1] = a[0] = 0;
  return a;
}
ll reverse(ll n) {
  ll s = 0;
  while (n > 0) {
    ll t = n % 10;
    s = s * 10 + t;
    n /= 10;
  }
  return s;
}
int count_setbits(int N)

{
  int cnt = 0;

  while (N > 0)

  {

    cnt += (N & 1);

    N = N >> 1;
  }

  return cnt;
}
ll power(ll x, ll y) {
  int res = 1; // Initialize result

  x = x % mod; // Update x if it is more than or
               // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % mod;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % mod;
  }
  return res;
}

void BellmanFord(vector<vector<ll>> &graph, int V, int E, int src) {
  // Initialize distance of all vertices as infinite.
  int dis[V];
  for (int i = 0; i < V; i++)
    dis[i] = INT_MAX;

  // initialize distance of source as 0
  dis[src] = 0;

  // Relax all edges |V| - 1 times. A simple
  // shortest path from src to any other
  // vertex can have at-most |V| - 1 edges
  for (int i = 0; i < V - 1; i++) {

    for (int j = 0; j < E; j++) {
      if (dis[graph[j][0]] + graph[j][2] < dis[graph[j][1]])
        dis[graph[j][1]] = dis[graph[j][0]] + graph[j][2];
    }
  }

  // check for negative-weight cycles.
  // The above step guarantees shortest
  // distances if graph doesn't contain
  // negative weight cycle.  If we get a
  // shorter path, then there is a cycle.
  for (int i = 0; i < E; i++) {
    int x = graph[i][0];
    int y = graph[i][1];
    int weight = graph[i][2];
    if (dis[x] != INT_MAX && dis[x] + weight < dis[y])
      cout << "Graph contains negative"
              " weight cycle"
           << endl;
  }
}
int main() {
  ll n;
  cin >> n;
  ll no = sieve(n)[n];
  if (no = 1)
    cout << 1 << "\\n";
  vector<ll> prime = primeFactorize(n);
  unordered_map<ll, ll> mp;
  for (ll i : prime) {
    mp[i]++;
  }
  ll res = 0;
  for (auto i : mp) {
    ll fac = i.second;
    ll j = 1;
    while ((j * (j + 1) / 2) <= fac)
      j++;
    j -= 1;
    res += j;
  }
  cout << res << "\\n";
}