alexjercan/bugnet huggingface dataset:
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<ll> factorList(ll x) {
    vector<ll> res;
    for (int p : primes) {
      while (x % p == 0) {
        res.push_back(p);
        x /= p;
      }
    }
    if (x != 1)
      res.push_back(x);
    return res;
  }
  vector<pair<ll, int>> factor(ll x) {
    vector<ll> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<pair<ll, int>> res(1, P(fl[0], 0));
    for (ll p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

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

  vector<pair<ll, int>> fs;
  for (ll i = 2; i * i <= n; ++i) {
    int x = 0;
    while (n % i == 0) {
      n /= i;
      ++x;
    }
    fs.emplace_back(i, x);
  }
  if (n != 1)
    fs.emplace_back(n, 1);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (int i = 2; i * i < n; i++) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  auto a = factorize(n);
  ll ans = 0;
  for (auto x : a) {
    ll e = 1;
    while (x.second - e >= 0) {
      x.second -= e;
      e++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<int64_t> v;
  for (int64_t i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int64_t cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      v.push_back(cnt);
      if (n == 1) {
        break;
      }
    }
  }
  if (n != 1) {
    v.push_back(1);
  }
  int64_t ans = 0;
  for (auto u : v) {
    int64_t i = 1;
    while (u >= i) {
      u = u - i;
      i++;
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t n;
  cin >> n;
  vector<int> v;
  for (int64_t i = 2; i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      v.push_back(cnt);
      if (n == 1) {
        break;
      }
    }
  }
  int ans = 0;
  for (int u : v) {
    int i = 1;
    while (u >= i) {
      u = u - i;
      i++;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int, long long int>, null_type,
             less<pair<long long int, long long int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

bool check(long long int a) {
  for (int i = 2; i <= sqrt(a); i++) {
    if (a % i == 0)
      return 0;
  }
  return 1;
}
void go() {
  long long int n;
  cin >> n;
  long long int i = 2;
  vector<long long int> f;
  long long int prev = n;
  if (n == 1) {
    cout << 0;
    return;
  }
  if (check(n)) {
    cout << 1;
    return;
  }
  while (n > 1) {
    if (prev != n && check(n)) {
      f.push_back(1);
      break;
    } else if ((n % i == 0) && check(i)) {
      // cout<<i<<endl;
      prev = n;
      long long int cnt = 0;
      while (n % i == 0)
        cnt++, n /= i;
      f.push_back(cnt);
    }
    i++;
  }
  long long int ans = 0;
  for (int i = 0; i < f.size(); i++) {
    // cout<<f[i]<<endl;
    long long int z = 1;
    long long int c = 2;
    while (z <= f[i])
      z += c, c++, ans++;
  }
  cout << ans;
}
int main() {
  // FIO;
  // int t;
  // cin>>t;
  // while(t--)
  go();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int, long long int>, null_type,
             less<pair<long long int, long long int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

bool check(long long int a) {
  for (int i = 2; i <= sqrt(a); i++) {
    if (a % i == 0)
      return 0;
  }
  return 1;
}
void go() {
  long long int n;
  cin >> n;
  long long int i = 2;
  vector<long long int> f;
  while (n > 1) {
    if (check(n)) {
      f.push_back(1);
      break;
    } else if (i <= 1000001 && (n % i == 0) && check(i)) {
      // cout<<i<<endl;
      int cnt = 0;
      while (n % i == 0)
        cnt++, n /= i;
      f.push_back(cnt);
    }
    i++;
  }
  int ans = 0;
  for (int i = 0; i < f.size(); i++) {
    // cout<<f[i]<<endl;
    int z = 1;
    int c = 2;
    while (z <= f[i])
      z += c, c++, ans++;
  }
  cout << ans;
}
int main() {
  // FIO;
  // int t;
  // cin>>t;
  // while(t--)
  go();
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 9;

inline int read() {
  char c = getchar();
  int tot = 1;
  while ((c < '0' || c > '9') && c != '-')
    c = getchar();
  if (c == '-') {
    tot = -1;
    c = getchar();
  }
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * tot;
}

int _;

//////////////////////////////////////////////////////////////////////////
ll vis[maxn], prime[maxn];
//////////////////////////////////////////////////////////////////////////
int main() {
  ll n;
  scanf("%lld", &n);
  ll n_ = sqrt(n), cnt = 0;
  for (ll i = 2; i <= n_; i++) {
    if (vis[i])
      continue;
    prime[++cnt] = i;
    for (ll j = 2; j <= n_ / i; j++)
      vis[i * j] = 1;
  }
  ll ans = 0;
  for (ll i = 1; i <= cnt; i++) {
    ll sum = 0;
    ll pr = prime[i];
    while (n % pr == 0) {
      n /= pr;
      sum++;
    }
    ll a = sqrt(sum * 2);
    if (a * (a + 1) > sum * 2)
      a--;
    ans += a;
  }
  if (n != 1)
    ans++;
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 9;

inline int read() {
  char c = getchar();
  int tot = 1;
  while ((c < '0' || c > '9') && c != '-')
    c = getchar();
  if (c == '-') {
    tot = -1;
    c = getchar();
  }
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * tot;
}

int _;

//////////////////////////////////////////////////////////////////////////
int vis[maxn], prime[maxn];
//////////////////////////////////////////////////////////////////////////
int main() {
  ll n;
  scanf("%lld", &n);
  ll n_ = sqrt(n), cnt = 0;
  for (ll i = 2; i <= n_; i++) {
    if (vis[i])
      continue;
    prime[++cnt] = i;
    for (int j = 2; j <= n / i; j++)
      vis[i * j] = 1;
  }
  int ans = 0;
  for (int i = 1; i <= cnt; i++) {
    int sum = 0;
    int pr = prime[i];
    while (n % pr == 0) {
      n /= pr;
      sum++;
    }
    int a = sqrt(sum * 2);
    if (a * (a + 1) > sum * 2)
      a--;
    ans += a;
  }
  if (n != 1)
    ans++;
  printf("%d\\n", ans);
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>

int main() {
  int64_t N_;
  std::cin >> N_;
  std::vector<int64_t> arr;
  if (N_ == 1)
    std::cout << 0;
  else {
    int64_t N = N_;

    int64_t limit = std::sqrt(N) + 1;

    for (int i = 2; i <= limit; ++i) {
      if (i > N)
        break;

      if (N % i == 0) {
        int64_t count = 0;
        while (N % i == 0) {
          ++count;
          N /= i;
        }
        arr.emplace_back(count);
      }
    }

    if (N > limit)
      arr.emplace_back(1);

    int64_t sum = 0;
    for (unsigned i = 0; i < arr.size(); ++i) {
      int64_t j = 1;
      while (1) {
        arr[i] -= j;
        if (arr[i] < 0)
          break;
        ++j;
        ++sum;
      }
    }

    std::cout << sum;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

int main() {
  int64_t N_;
  std::cin >> N_;
  std::vector<int64_t> arr;
  if (N_ == 1)
    std::cout << 0;
  else {
    int64_t N = N_;

    for (int i = 2; i <= N_; ++i) {
      if (i > N || i * i > N_)
        break;

      if (N % i == 0) {
        int64_t count = 0;
        while (N % i == 0) {
          ++count;
          N /= i;
        }
        arr.emplace_back(count);
      }
    }

    if (N == N_)
      arr.emplace_back(1);

    int64_t sum = 0;
    for (unsigned i = 0; i < arr.size(); ++i) {
      int64_t j = 1;
      while (1) {
        arr[i] -= j;
        if (arr[i] < 0)
          break;
        ++j;
        ++sum;
      }
    }

    std::cout << sum;
  }
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long ll;

vector<pair<ll, int>> factor(ll x) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= x; i++) {
    int cnt = 0;
    while (x % i == 0)
      x /= i, cnt++;
    if (cnt)
      res.emplace_back(i, cnt);
  }
  if (x != 1)
    res.emplace_back(x, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs = factor(n);
  int ans = 0;
  for (pair<ll, int> p : fs) {
    // cout << p[i].first << ' ' << p[i].second << endl;
    int b = 1;
    int x = p.second;
    while (x >= b) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long ll;

vector<pair<ll, int>> factor(ll x) {
  vector<pair<ll, int>> res;
  for (int i = 2; i * i <= x; i++) {
    int cnt = 0;
    while (x % i == 0)
      x /= i, cnt++;
    if (cnt)
      res.emplace_back(i, cnt);
  }
  if (x != 1)
    res.emplace_back(x, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs = factor(n);
  int ans = 0;
  for (pair<ll, int> p : fs) {
    // cout << p[i].first << ' ' << p[i].second << endl;
    int b = 1;
    int x = p.second;
    while (x >= b) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

// typedef pair<int, int> p;
typedef long long ll;

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

  vector<pair<ll, int>> fs;
  for (ll i = 2; i * i <= n; ++i) {
    int x = 0;
    while (n % i == 0) {
      n /= i;
      ++x;
    }
    fs.emplace_back(i, x);
  }
  if (n != 1)
    fs.emplace_back(n, 1);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

vector<pair<ll, int>> factor(ll x) {
  vector<pair<ll, int>> res;
  for (int i = 2; i * i < x; i++) {
    int cnt = 0;
    while (x % i == 0)
      x /= i, cnt++;
    if (cnt)
      res.emplace_back(i, cnt);
  }
  if (x != 1)
    res.emplace_back(x, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs = factor(n);
  int ans = 0;
  for (pair<ll, int> p : fs) {
    // cout << p[i].first << ' ' << p[i].second << endl;
    int b = 1;
    int x = p.second;
    while (x >= b) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

bool isPrime(int x) {
  int i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}

signed main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << 0;
    return 0;
  }
  if (isPrime(N)) {
    cout << 1;
    return 0;
  }

  int ans = 0;
  for (int i = 2; i <= N; i++) {
    if (N % i == 0) {
      int cnt = 0;
      while (N % i == 0) {
        cnt++;
        N /= i;
      }
      int a = sqrt(1 + 8 * cnt);
      int b = (-1 + a) / 2;
      ans += b;
    } else {
      if (i * i > N) {
        ans++;
        break;
      }
    }
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

bool isPrime(int x) {
  int i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}

signed main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << 0;
    return 0;
  }
  if (isPrime(N)) {
    cout << 1;
    return 0;
  }

  int ans = 0;
  for (int i = 2; i <= N; i++) {
    if (N % i == 0) {
      int cnt = 0;
      while (N % i == 0) {
        cnt++;
        N /= i;
      }
      int a = sqrt(1 + 8 * cnt);
      int b = (-1 + a) / 2;
      ans += b;
    }
  }
  cout << ans;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\\n'
typedef pair<int, int> P;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  map<ll, int> m;
  ll tmp = n;
  for (ll i = 2; i * i < n; i++) {
    if (tmp % i == 0) {
      int cnt = 0;
      while (tmp % i == 0) {
        cnt++;
        tmp /= i;
      }
      m[i] = cnt;
    }
  }
  if (tmp > 1) {
    m[tmp] += 1;
  }
  ll res = 0;
  for (auto p : m) {
    for (int i = 1; i < 50; i++) {
      if (p.second >= i) {
        res++;
        p.second -= i;
      }
    }
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\\n'
typedef long long ll;
typedef pair<ll, ll> P;
struct Sieve {
  vector<int> smallest_factor;
  vector<int> smallest_power;
  vector<int> moebius;
  vector<int> totient;
  vector<bool> prime;
  vector<int> primes;
  Sieve(int m)
      : smallest_factor(m + 1), smallest_power(m + 1), moebius(m + 1),
        totient(m + 1), prime(m + 1, true) {
    moebius[1] = totient[1] = 1;
    prime[0] = prime[1] = false;

    for (int i = 2; i <= m; i++) {
      if (prime[i]) {
        smallest_factor[i] = i;
        smallest_power[i] = 1;
        moebius[i] = -1;
        totient[i] = i - 1;
        primes.push_back(i);
      }

      for (int p : primes) {
        if (p > smallest_factor[i] || i * p > m)
          break;
        prime[i * p] = false;
        smallest_factor[i * p] = p;
        smallest_power[i * p] =
            smallest_factor[i] == p ? smallest_power[i] + 1 : 1;
        moebius[i * p] = smallest_factor[i] == p ? 0 : -moebius[i];
        totient[i * p] =
            smallest_factor[i] == p ? p * totient[i] : (p - 1) * totient[i];
      }
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  priority_queue<P, vector<P>, greater<P>> que;
  Sieve s(1000000);
  for (auto i : s.primes) {
    que.push(P(i, i));
  }
  map<ll, ll> dp;
  dp[n] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    for (ll j = p.first; j <= 1000000; j *= p.first) {
      for (auto pp : dp) {
        if (pp.first % j == 0) {
          dp[pp.first / j] = max(dp[pp.first / j], pp.second + 1);
        }
      }
    }
  }
  ll ans = 0;
  for (auto p : dp) {
    if (p.first > 1000000) {
      ans = max(ans, p.second + 1);
    } else {
      ans = max(ans, p.second);
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int cal(int x) {
  int j = 1;
  while (x - j >= 0) {
    x -= j;
    j++;
  }
  return j - 1;
}
int main() {
  long long n;
  cin >> n;
  int m = int(sqrt(n));
  int a[m + 1];
  for (int i = 1; i <= m; i++)
    a[i] = 0;
  while (n % 2 == 0) {
    n /= 2;
    a[2]++;
  }
  int t = 3, ans = 0;
  while (n != 1 && t <= m) {
    while (n % t == 0) {
      n /= t;
      a[t]++;
    }
    t += 2;
  }
  for (int i = 1; i <= m; i++)
    if (a[i] != 0)
      ans += cal(a[i]);
  if (n == 1)
    cout << ans << endl;
  else
    cout << ans + 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int main() {
  long long i, j;
  long long n;
  cin >> n;
  bool a[n + 1];
  memset(a, true, sizeof(a));
  for (i = 2; i * i <= n; ++i)
    if (a[i] == 1)
      for (j = i + i; j <= n; j += i)
        a[j] = 0;
  long long s[maxn + 1], curr = 0;
  s[0] = 0;
  for (i = 1; i <= maxn; ++i) {
    curr += i;
    s[i] = curr;
  }
  long long x = 0, ans = 0;
  for (i = 2; i * i <= n, n > 1; ++i)
    if (a[i] == 1) {
      while (n % i == 0) {
        n /= i;
        x++;
      }
      long long pos = upper_bound(s + 1, s + maxn + 1, x) - s;
      ans += pos - 1;
      x = 0;
    }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {

  ll n;
  cin >> n;

  ll count = 0;

  vector<pair<ll, int>> nums;
  ll now = 1;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  while (1) {
    now++;
    if (now * now > n) {
      if (n != 1) {
        nums.emplace_back(n, 1);
      }
      break;
    }

    if (n % now == 0) {
      count = 1;
      n /= now;
      while (1) {
        if (n % now != 0) {
          nums.emplace_back(now, count);
          break;
        } else if (n % now == 0) {
          count++;
          n /= now;
        }
      }
    }
  }

  ll time = 0;
  ll ans = 0;
  ll fi;
  ll sec;
  for (auto &x : nums) {
    // cout << x.first << ":" << x.second << endl;
    fi = x.first;
    sec = x.second;
    time = 0;
    while (1) {
      time++;
      if (time > sec) {
        break;
      } else {
        ans++;
        sec = sec - time;
        // cout << "time:" << time << endl;
        // cout << "sec:" << sec << endl;
        // cout << "ans:" << ans << endl;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {

  ll num;
  cin >> num;
  ll numCP = num;
  ll count = 1;

  map<ll, ll> mp;
  vector<pair<ll, ll>> nums;
  ll time;

  if (num == 1) {
    cout << 0 << endl;
    return 0;
  } else {
    while (1) {
      count++;
      time = 0;
      if (count * count > numCP && nums.size() == 0) {
        nums.emplace_back(numCP, 1);
        break;
      }
      if (num % count == 0) {
        time++;
        num /= count;
        while (1) {
          if (num % count != 0) {
            nums.emplace_back(count, time);
            break;
          } else if (num % count == 0) {
            time++;
            num /= count;
          }
        }
      }
      if (num == 1) {
        break;
      }
    }

    for (auto &i : nums) {
      ll t = 1;
      ll now = i.first;
      mp[i.first]++;
      i.second--;
      while (1) {
        t++;
        if (i.second < t) {
          break;
        } else {
          now *= i.first;
          mp[now]++;
          i.second -= t;
        }
      }
    }
    cout << endl << mp.size() << endl;
  }
}