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

/*
___ is a raging sadist.
*/

// Destroy all WA at test 2

#include <bits/stdc++.h>
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define endl "\\n"
#define PI 3.14159265
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;

ll power(ll x, ll y) {
  ll res = 1;

  while (y > 0) {

    if (y & 1)
      res = (long long)(res * x);

    y = y >> 1;

    if (x <= 100000000)
      x = (long long)(x * x);

    // cout<<x<<'\\n';
  }
  return res;
}

int main() {

  fastio();

  ll n;
  cin >> n;

  ll temp = n;

  vector<ll> facts;
  ll tot = 0;
  vector<ll> cnt;

  for (int i = 2; i <= sqrt(n); i++) {
    ll cn = 0;
    while (temp % i == 0) {
      temp /= i;
      cn += 1;
    }
    cnt.pb(cn);
  }

  if (temp != n && temp != 1)
    cnt.pb(1);

  vector<ll> sums(60);

  if (temp != n) {
    for (int i = 0; i < 60; i++)
      sums[i] = ((i + 1) * (i + 2)) / 2;

    for (int i = 0; i < cnt.size(); i++) {
      if (cnt[i] > 0) {
        ll pos = lower_bound(sums.begin(), sums.end(), cnt[i]) - sums.begin();
        if (sums[pos] == cnt[i])
          tot += pos + 1;
        else
          tot += pos;
      }
    }
  }

  if (n == 1)
    cout << 0;
  else if (temp == n)
    cout << 1;
  else
    cout << tot;

  return 0;
}

Error: WA

Fixed submission:

/*
___ is a raging sadist.
*/

// Destroy all WA at test 2

#include <bits/stdc++.h>
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define endl "\\n"
#define PI 3.14159265
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;

ll power(ll x, ll y) {
  ll res = 1;

  while (y > 0) {

    if (y & 1)
      res = (long long)(res * x);

    y = y >> 1;

    if (x <= 100000000)
      x = (long long)(x * x);

    // cout<<x<<'\\n';
  }
  return res;
}

ll cnt[10000005] = {0};

int main() {

  fastio();

  ll n;
  cin >> n;

  ll temp = n;

  vector<ll> facts;
  ll tot = 0;

  for (int i = 2; i <= sqrt(n); i++) {
    while (temp % i == 0) {
      temp /= i;
      cnt[i] += 1;
    }
  }

  if (temp != n && temp != 1)
    cnt[temp] += 1;

  vector<ll> sums(60);

  if (temp != n) {
    for (int i = 0; i < 60; i++)
      sums[i] = ((i + 1) * (i + 2)) / 2;

    for (int i = 2; i <= sqrt(n); i++) {
      if (cnt[i] > 0) {
        ll pos = lower_bound(sums.begin(), sums.end(), cnt[i]) - sums.begin();
        if (sums[pos] == cnt[i])
          tot += pos + 1;
        else
          tot += pos;
      }
    }
  }

  if (n == 1)
    cout << 0;
  else if (temp == n)
    cout << 1 << endl;
  else
    cout << tot;

  return 0;
}