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

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m) {
  if ((a + b) >= m)
    return (a + b) % m;
  return a + b;
}

inline ll mul(ll a, ll b, ll m) {
  if ((a * b) < m)
    return a * b;
  return (a * b) % m;
}

ll power(ll x, ll y, ll m) {
  ll res = 1;
  x = x % m;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % m;
    y = y >> 1;
    x = (x * x) % m;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  ll x = n;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    ll res = 1;
    for (ll j = 1; j <= 50; j++) {
      if ((j * (j + 1)) / 2 <= cnt)
        res = j;
    }
    ans += res;
  }
  if (n > 1)
    ans++;
  cout << ans;
}

int main() {
  fastio;
  int t;

  t = 1;
  // cin >> t;
  // int test=t;
  while (t-- > 0) {
    // cout<<"Case #"<<(test-t)<<": ";
    solve();
    cout << newl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m) {
  if ((a + b) >= m)
    return (a + b) % m;
  return a + b;
}

inline ll mul(ll a, ll b, ll m) {
  if ((a * b) < m)
    return a * b;
  return (a * b) % m;
}

ll power(ll x, ll y, ll m) {
  ll res = 1;
  x = x % m;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % m;
    y = y >> 1;
    x = (x * x) % m;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  vi sieve(1e6 + 1, 0);
  vl prime;
  for (int p = 2; p * p <= 1e6; p++) {
    if (sieve[p] == 0) {
      sieve[p] = 1;
      prime.pb(p);
      for (int i = p * p; i <= 1e6; i += p)
        sieve[i] = 1;
    }
  }
  sort(all(prime));
  vl val;
  for (int i = 0; i < sz(prime); i++) {
    ll p = prime[i];
    ll v = p;
    while (v < (ll)1e12) {
      val.pb(v);
      v *= p;
    }
  }
  sort(all(val));
  ll cnt = 0;
  ll c = 0;
  while (n > 1) {
    ll p = val[c];
    if (p > n) {
      cnt++;
      break;
    }
    if (n % p == 0) {
      n /= p;
      cnt++;
    }
    c++;
  }
  cout << cnt;
}

int main() {
  fastio;
  int t;

  t = 1;
  // cin >> t;
  // int test=t;
  while (t-- > 0) {
    // cout<<"Case #"<<(test-t)<<": ";
    solve();
    cout << newl;
  }

  return 0;
}