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

#line 1 "d.cpp"
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for (ll i = l; i < (ll)r; i++)
#define per(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define per3(i, l, r) for (ll i = (ll)r - 1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template <class T, class U> inline void cmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> inline void cmin(T &a, U b) {
  if (a > b)
    a = b;
}
constexpr char el = '\\n';
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &i : v)
    is >> i;
  return is;
}
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;
#line 3 "../../library/prime_factorization.hpp"

map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> m;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      m[i]++;
      n /= i;
    }
  }
  if (n != 1)
    m[n]++;
  return m;
}
#line 3 "d.cpp"

int main() {
  ll n;
  cin >> n;

  ll ans = 0;

  auto m = prime_factorization(n);
  for (auto &&i : m) {
    ll t = i.second;
    ll cnt = 1;
    while ((cnt + 1) * (cnt + 2) / 2 <= t) {
      cnt++;
    }
    ans += cnt;
  }

  cout << ans << el;
}


Error: TLE

Fixed submission:

#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for (ll i = l; i < (ll)r; i++)
#define per(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define per3(i, l, r) for (ll i = (ll)r - 1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template <class T, class U> inline void cmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> inline void cmin(T &a, U b) {
  if (a > b)
    a = b;
}
constexpr char el = '\\n';
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &i : v)
    is >> i;
  return is;
}
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;
#line 3 "../../library/prime_factorization.hpp"

map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> m;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      m[i]++;
      n /= i;
    }
  }
  if (n != 1)
    m[n]++;
  return m;
}
#line 3 "d.cpp"

int main() {
  ll n;
  cin >> n;

  ll ans = 0;

  auto m = prime_factorization(n);
  for (auto &&i : m) {
    ll t = i.second;
    ll cnt = 1;
    while ((cnt + 1) * (cnt + 2) / 2 <= t) {
      cnt++;
    }
    ans += cnt;
  }

  cout << ans << el;
}