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

#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define endl "\\n"
#define eb emplace_back
#define pb push_back
#define mk make_pair
#define mt make_tuple

#define Umap unordered_map
#define graph vector<vector<int>>

#define NO cout << "NO" << endl
#define YES cout << "YES" << endl

#define INF 1e9 + 5
#define N 40001

bool sortbysec(const tuple<int, int, int> &a, const tuple<int, int, int> &b) {
  return (get<1>(a) < get<1>(b));
}

const int MAXN = 0;
int spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++)
    spf[i] = i;

  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < MAXN; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}
bool custom(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first > b.first;
}

// A.reize(unique(A.begin(),A.end())- A.begin());
#define int long long
vector<int> primes;
const int m = (int)1e4 + 1;
bool prime[m];

void solve() {
  int n;
  cin >> n;
  if (n <= 1) {
    cout << 0 << endl;
    return;
  }
  int ans = 0;

  int req = 1;
  int cnt = 0;
  while (n && n % 2 == 0) {
    cnt++;
    if (cnt == req) {
      ans++;
      req++;
      cnt = 0;
    }
    n /= 2;
  }

  for (int i = 3; i * i <= n; i += 2) {
    int req = 1;
    int cnt = 0;
    while (n && n % i == 0) {
      cnt++;
      if (cnt == req) {
        ans++;
        req++;
        cnt = 0;
      }
      n /= i;
    }
  }
  if (n > 2)
    ans++;
  cout << ans << endl;
}

signed main() {
  IOS;
  int t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

vector<int> getFactorization(int x) {

  vector<int> primeFactors;
  while (x > 1) {
    primeFactors.pb(spf[x]);
    x /= spf[x];
  }
  return primeFactors;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define endl "\\n"
#define eb emplace_back
#define pb push_back
#define mk make_pair
#define mt make_tuple

#define Umap unordered_map
#define graph vector<vector<int>>

#define NO cout << "NO" << endl
#define YES cout << "YES" << endl

#define INF 1e9 + 5
#define N 40001

bool sortbysec(const tuple<int, int, int> &a, const tuple<int, int, int> &b) {
  return (get<1>(a) < get<1>(b));
}

const int MAXN = 0;
int spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++)
    spf[i] = i;

  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < MAXN; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}
bool custom(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first > b.first;
}

// A.reize(unique(A.begin(),A.end())- A.begin());
#define int long long
vector<int> primes;
const int m = (int)1e4 + 1;
bool prime[m];

void SieveOfEratosthenes() {
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= m; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= m; i += p)
        prime[i] = false;
    }
  }

  // Print all prime numbers
  for (int p = 2; p <= m; p++)
    if (prime[p])
      primes.pb(p);
}
bool prim(int n) {
  if (n < 2)
    return 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
void solve() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1 << endl;
    return;
  }
  if (prim(n)) {
    cout << 1 << endl;
    return;
  }
  primes.clear();
  SieveOfEratosthenes();
  int ans = 0;
  for (int prime : primes) {
    int req = 1;
    int cnt = 0;
    if (n / prime == 0)
      break;
    while (n % prime == 0) {
      cnt++;
      if (cnt == req) {
        req++;
        cnt = 0;
        ans++;
      }
      n /= prime;
    }
  }
  cout << ans << endl;
}

signed main() {
  IOS;
  int t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

vector<int> getFactorization(int x) {

  vector<int> primeFactors;
  while (x > 1) {
    primeFactors.pb(spf[x]);
    x /= spf[x];
  }
  return primeFactors;
}