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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define mod 1e9 + 7
#define MOD 998244353
#define ll long long
#define mp make_pair
#define F first
#define S second
#define t()                                                                    \\
  int test;                                                                    \\
  cin >> test;                                                                 \\
  while (test--)
#define ii pair<int, int>
#define que_max priority_queue<int>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
  // use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

vector<bool> isprime(1e7 + 1, true);

vector<ll int> primes;

void sieve() {
  ll int i, j;
  isprime[0] = false;
  isprime[1] = false;

  for (i = 2; i <= 1e7; i++) {
    if (isprime[i]) {
      primes.push_back(i);

      for (j = i * i; j <= 1e7; j += i) {
        isprime[j] = false;
      }
    }
  }
}

vector<int> primefactors(ll int N) {
  vector<int> factors;
  ll pf_idx = 0, pf = primes[pf_idx];

  int cnt = 0;
  while (pf * pf <= N) {
    cnt = 0;
    while (N % pf == 0) {
      N /= pf;
      cnt++;
    }
    factors.push_back(cnt);
    if (pf_idx + 1 < primes.size())
      pf = primes[++pf_idx];
    else
      break;
  }
  if (N != 1)
    factors.push_back(1);
  return factors;
}

int32_t main()

{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;

  // t()
  {

    sieve();

    ll int n;

    cin >> n;

    vector<int> result = primefactors(n);

    ll ans = 0;

    for (int i = 0; i < result.size(); i++) {
      int x = result[i];

      int cnt = 1;

      while (x >= cnt) {
        ans++;
        x -= cnt;
        cnt++;
      }
    }

    cout << ans;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define mod 1e9 + 7
#define MOD 998244353
#define ll long long
#define mp make_pair
#define F first
#define S second
#define t()                                                                    \\
  int test;                                                                    \\
  cin >> test;                                                                 \\
  while (test--)
#define ii pair<int, int>
#define que_max priority_queue<int>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
  // use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

vector<bool> isprime(1e6 + 1, true);

vector<ll int> primes;

void sieve() {
  ll int i, j;
  isprime[0] = false;
  isprime[1] = false;

  for (i = 2; i <= 1e6; i++) {
    if (isprime[i]) {
      primes.push_back(i);

      for (j = i * i; j <= 1e6; j += i) {
        isprime[j] = false;
      }
    }
  }
}

vector<int> primefactors(ll int N) {
  vector<int> factors;
  ll pf_idx = 0, pf = primes[pf_idx];

  int cnt = 0;
  while (pf * pf <= N) {
    cnt = 0;
    while (N % pf == 0) {
      N /= pf;
      cnt++;
    }
    factors.push_back(cnt);
    pf = primes[++pf_idx];
  }
  if (N != 1)
    factors.push_back(1);
  return factors;
}

int32_t main()

{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;

  // t()
  {

    sieve();

    ll int n;

    cin >> n;

    vector<int> result = primefactors(n);

    ll ans = 0;

    for (int i = 0; i < result.size(); i++) {
      int x = result[i];

      int cnt = 1;

      while (x >= cnt) {
        ans++;
        x -= cnt;
        cnt++;
      }
    }

    cout << ans;
  }
}