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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> using lim = numeric_limits<T>;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,
                              tree_order_statistics_node_update>;

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

ll solve(ll x) {
  ll lo = 0;
  ll hi = 1e9;
  ll ans = 0;
  while (lo <= hi) {
    ll mid = hi - (hi - lo) / 2;
    if (mid * (mid + 1) / 2 <= x) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  unordered_map<ll, ll> factorized;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      factorized[i]++;
    }
  }
  if (n > 1)
    factorized[n]++;

  ll ans = 0;
  for (auto it = factorized.begin(); it != factorized.end(); it++) {
    ans += solve(it->second);
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> using lim = numeric_limits<T>;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,
                              tree_order_statistics_node_update>;

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

ll solve(int x) {
  ll lo = 0;
  ll hi = 1e9;
  ll ans = 0;
  while (lo <= hi) {
    ll mid = hi - (hi - lo) / 2;
    if (mid * (mid + 1) / 2 <= x) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  map<int, int> factorized;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      factorized[i]++;
    }
  }
  if (n > 1)
    factorized[n]++;

  ll ans = 0;
  for (auto it = factorized.begin(); it != factorized.end(); it++) {
    ans += solve(it->second);
  }
  cout << ans << "\\n";
}