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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll> VI;
typedef vector<bool> VB;
typedef pair<ll, ll> P;
typedef pair<double, double> P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit, A) for (int bit = A;; bit = (bit - 1) & A)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a) > ((ll)b) ? (a) : (b))
#define c_min(a, b) (((ll)a) < ((ll)b) ? (a) : (b))
#define chmax(x, a) x = c_max(x, a)
#define chmin(x, a) x = c_min(x, a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x)                                                                   \\
  { cout << #x << " = " << (x) << endl; }
#define fi first
#define se second
#define MAX 100100 // 5
#define MAX2 200100
#define MAX_6 1001001       // 6
#define MAX_7 10010010      // 7
#define SENTINEL 2000000000 // 9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\\n'
#define greater greater<int>()
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a * b / GCD(a, b); }
// g++ -o a a.cpp -Wall -lm -std=c++14
vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<pair<long long, long long>> res = prime_factorize(n);
  ll ans = 0;
  for (auto v : res) {
    ll e = v.se;
    ll tmp = 0, cur = 1;
    while (e >= cur)
      e -= cur++, ++tmp;
    ans += tmp;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll> VI;
typedef vector<bool> VB;
typedef pair<ll, ll> P;
typedef pair<double, double> P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit, A) for (int bit = A;; bit = (bit - 1) & A)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a) > ((ll)b) ? (a) : (b))
#define c_min(a, b) (((ll)a) < ((ll)b) ? (a) : (b))
#define chmax(x, a) x = c_max(x, a)
#define chmin(x, a) x = c_min(x, a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x)                                                                   \\
  { cout << #x << " = " << (x) << endl; }
#define fi first
#define se second
#define MAX 100100 // 5
#define MAX2 200100
#define MAX_6 1001001       // 6
#define MAX_7 10010010      // 7
#define SENTINEL 2000000000 // 9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\\n'
#define greater greater<int>()
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a * b / GCD(a, b); }
// g++ -o a a.cpp -Wall -lm -std=c++14
map<int, int> prime_factor(ll n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}
int main() {
  ll n;
  cin >> n;
  map<int, int> res = prime_factor(n);
  ll c = 0;

  for (auto v : res) {
    int m = v.se;
    int id = 1;
    while (1) {
      if (m >= id) {
        m -= id;
        id++;
        c++;
      } else {
        break;
      }
    }
  }
  cout << c << endl;
}