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

#include <bits/stdc++.h>
#define ll long long
#define db double
#define ldb long double
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define xh1(a, b) for (int i = a; i < b; i++)
#define xh2(a, b) for (int j = a; j < b; j++)
#define stlbl(a) for (it = a.begin(); it != a.end(); it++)
#define dzkt                                                                   \\
  int T;                                                                       \\
  cin >> T;                                                                    \\
  while (T--)
#define iosks                                                                  \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
int pow2(int a, int b) {
  int s = 1;
  while (b) {
    if (b & 1)
      s *= a;
    a *= a;
    b /= 2;
  }
  return s;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
ll prime(ll x) {
  for (ll i = 2; i <= sqrt(x + 0.5); i++)
    if (x % i == 0)
      return 0;
  return 1;
}
const int N = 1e6, inf = 1e9 + 10;
const ll ma = 1e18;
char ch[N];
ll vis[N], a[N];
vector<ll> vec;
int main() {
  iosks;
  ll n;
  cin >> n;
  xh1(2, N) if (vis[i] == 0) {
    vec.push_back(i);
    for (int j = i + i; j < N; j += i)
      vis[j] = 1;
  }
  xh1(0, vec.size()) while (n % vec[i] == 0) { n /= vec[i], a[vec[i]]++; }
  ll ans = 0;
  if (n != 1)
    ans = 1;
  xh1(0, vec.size()) {
    ll k = a[vec[i]];
    if (k == 0)
      continue;
    ll j = sqrt(k) - 1;
    while (j * (j + 1) / 2 <= k)
      j++;
    ans += j - 1;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define db double
#define ldb long double
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define xh1(a, b) for (int i = a; i < b; i++)
#define xh2(a, b) for (int j = a; j < b; j++)
#define stlbl(a) for (it = a.begin(); it != a.end(); it++)
#define dzkt                                                                   \\
  int T;                                                                       \\
  cin >> T;                                                                    \\
  while (T--)
#define iosks                                                                  \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
int pow2(int a, int b) {
  int s = 1;
  while (b) {
    if (b & 1)
      s *= a;
    a *= a;
    b /= 2;
  }
  return s;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
ll prime(ll x) {
  for (ll i = 2; i <= sqrt(x + 0.5); i++)
    if (x % i == 0)
      return 0;
  return 1;
}
const int N = 2e5 + 10, inf = 1e9 + 10;
const ll ma = 1e18;
char ch[N];
map<ll, int> mp;
map<ll, int>::iterator it;
int main() {
  iosks;
  ll n;
  cin >> n;
  ll ans = 0, j = 2;
  while (n != 1) {
    if (prime(n))
      mp[n]++, n = 1;
    while (n % j == 0)
      n /= j, mp[j]++;
    ;
    j++;
  }
  stlbl(mp) {
    ll k = it->second;
    ll i = sqrt(k) - 1;
    while (i * (i + 1) / 2 <= k)
      i++;
    ans += i - 1;
  }
  cout << ans << endl;
  return 0;
}