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

#include <bits/stdc++.h>
#define bug1(x) cout << #x << " = " << x << endl
#define bug2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << endl
#define bug3(x, y, z)                                                          \\
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \\
       << z << endl
#define bug4(x, y, z, m)                                                       \\
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \\
       << z << " " << #m << " = " << m << endl

using namespace std;

class Debugger {
public:
  template <typename T>
  void printVector(vector<T> const &vec, bool printSize = true) {
    if (printSize) {
      cout << vec.size() << endl;
    }
    for (auto &elem : vec) {
      cout << elem << " ";
    }
    cout << endl;
  }

  template <typename T> void printMatrix(vector<vector<T>> const &matrix) {
    cout << matrix.size() << " ";
    if (!matrix.empty()) {
      cout << matrix[0].size();
    }
    cout << endl;
    for (auto &vec : matrix) {
      printVector(vec, false);
    }
    cout << endl;
  }
};

const int maxN = 10000005;
#define ll long long

class TaskD {
private:
  Debugger debugger;
  vector<ll> primes;
  void getPrimes() {
    vector<bool> vis(maxN, false);
    for (int i = 2; i < maxN; i++) {
      if (!vis[i]) {
        primes.push_back(i);
        for (int j = i; j < maxN; j += i) {
          vis[j] = true;
        }
      }
    }
  }

public:
  void solveOne(int it) {
    ll n;
    cin >> n;
    if (n == 1) {
      cout << 0 << endl;
      return;
    }
    getPrimes();
    int ans = 0;
    for (ll p : primes) {
      int e = 0;
      while (n % p == 0) {
        n /= p;
        e++;
      }
      int curr = 1;
      while (e > 0) {
        e -= curr;
        if (e >= 0) {
          ans++;
        }
        curr++;
      }
    }
    if (n > 1) {
      ans++;
    }
    cout << ans << endl;
  }

  void solve() {
    int tc = 1;
    for (int it = 1; it <= tc; it++) {
      solveOne(it);
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  TaskD solver;
  solver.solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define bug1(x) cout << #x << " = " << x << endl
#define bug2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << endl
#define bug3(x, y, z)                                                          \\
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \\
       << z << endl
#define bug4(x, y, z, m)                                                       \\
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \\
       << z << " " << #m << " = " << m << endl

using namespace std;

class Debugger {
public:
  template <typename T>
  void printVector(vector<T> const &vec, bool printSize = true) {
    if (printSize) {
      cout << vec.size() << endl;
    }
    for (auto &elem : vec) {
      cout << elem << " ";
    }
    cout << endl;
  }

  template <typename T> void printMatrix(vector<vector<T>> const &matrix) {
    cout << matrix.size() << " ";
    if (!matrix.empty()) {
      cout << matrix[0].size();
    }
    cout << endl;
    for (auto &vec : matrix) {
      printVector(vec, false);
    }
    cout << endl;
  }
};

const int maxN = 10000005;
#define ll long long

class TaskD {
private:
  Debugger debugger;
  vector<ll> primes;
  void getPrimes() {
    vector<bool> vis(maxN, false);
    for (int i = 2; i < maxN; i++) {
      if (!vis[i]) {
        primes.push_back(i);
        for (int j = i; j < maxN; j += i) {
          vis[j] = true;
        }
      }
    }
  }

public:
  void solveOne(int it) {
    ll n;
    cin >> n;
    if (n == 1) {
      cout << 0 << endl;
      return;
    }
    getPrimes();
    bool isPrime = true;
    for (ll p : primes) {
      if (n % p == 0) {
        isPrime = false;
      }
    }
    if (isPrime) {
      cout << 1 << endl;
      return;
    }
    int ans = 0;
    for (ll p : primes) {
      int e = 0;
      while (n % p == 0) {
        n /= p;
        e++;
      }
      int curr = 1;
      while (e > 0) {
        e -= curr;
        if (e >= 0) {
          ans++;
        }
        curr++;
      }
    }
    assert(n == 1);
    cout << ans << endl;
  }

  void solve() {
    int tc = 1;
    for (int it = 1; it <= tc; it++) {
      solveOne(it);
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  TaskD solver;
  solver.solve();
  return 0;
}