Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt,
// less) : if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*"))
// ) std::cout << "YES" << std::endl;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

std::vector<ll> pFactorization(ll n) {
  std::vector<ll> rtn;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    rtn.push_back(i);
    while (n % i == 0)
      n /= i;
  }
  if (n != 1)
    rtn.push_back(n);
  return rtn;
}

int main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  ll N;
  std::cin >> N;

  auto P = pFactorization(N);
  std::vector<int> e(sz(P));
  ll T = N;
  for (int i = 0; i < sz(P); i++) {
    int cnt = 0;
    while (T % P[i] == 0) {
      cnt++;
      T /= P[i];
    }
    e[i] = cnt;
  }

  int ans = 0;
  for (int i = 0; i < sz(P); i++) {
    int sum = 0;
    int j;
    for (j = 1; sum + j <= e[i]; j++)
      sum += j;
    ans += (j - 1);
    // std::cout << P[i] << " " << e[i] << " " << j-1 << std::endl;
  }
  std::cout << ans << std::endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt,
// less) : if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*"))
// ) std::cout << "YES" << std::endl;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

std::map<ll, ll> pFactorization(ll n) {
  std::map<ll, ll> rtn;
  for (int i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    while (n % i == 0) {
      n /= i;
      rtn[i]++;
    }
  }
  if (n != 1) {
    rtn[n] = 1;
  }
  return rtn;
}

int main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  ll N;
  std::cin >> N;

  auto P = pFactorization(N);

  int ans = 0;
  for (auto p : P) {
    ans += (int)((std::sqrt(8 * p.second + 1) - 1.) / 2.);
  }
  std::cout << ans << std::endl;
  return 0;
}