alexjercan/bugnet huggingface dataset:
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 FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
map<ll, ll> prime_factorization(long long n) {
  // map<ll,ll> first=素因数 second=first素因数の数
  map<ll, ll> res;
  for (int i = 2; i <= n / i; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
int main() {
  ll N;
  cin >> N;
  map<ll, ll> mp = prime_factorization(N);
  ll ans = 0;
  for (auto s : mp) {
    for (int i = 1; i <= s.second; i++) {
      ans++;
      s.second -= i;
    }
  }
  cout << ans << 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 FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
map<ll, ll> prime_factorization(long long n) {
  // map<ll,ll> first=素因数 second=first素因数の数
  map<ll, ll> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
int main() {
  ll N;
  cin >> N;
  map<ll, ll> mp = prime_factorization(N);
  ll ans = 0;
  for (auto s : mp) {
    for (int i = 1; i <= s.second; i++) {
      ans++;
      s.second -= i;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[70] = {};
int main() {
  ll n;
  cin >> n;
  vector<int> v;
  a[1] = 1;
  for (int i = 2; i < 70; i++) {
    a[i] = a[i - 1] + i;
  }
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      v.push_back(cnt);
    }
  }
  if (n > 1)
    v.push_back(1);
  sort(v.begin(), v.end());
  int ans = 0;
  int p = 1;
  for (int i = 0; i < (int)v.size(); i++) {
    while (a[p] <= v[i])
      p++;
    ans += p - 1;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[70] = {};
int main() {
  ll n;
  cin >> n;
  vector<int> v;
  a[1] = 1;
  for (int i = 2; i < 70; i++) {
    a[i] = a[i - 1] + i;
  }
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      v.push_back(cnt);
    }
  }
  if (n > 1)
    v.push_back(1);
  sort(v.begin(), v.end());
  int ans = 0;
  int p = 1;
  for (int i = 0; i < (int)v.size(); i++) {
    while (a[p] <= v[i])
      p++;
    ans += p - 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

using namespace std;
#include <bits/stdc++.h>
#include <iostream>
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MAX 1000000
#define ll long long

void abc() {
  FIO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void sieve(vector<int> &prime) {
  for (int i = 2; i * i <= MAX; i++) {
    if (prime[i] == 1) {
      for (int j = i * i; j < MAX; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  abc();

  ll n;
  cin >> n;
  ll m = n;

  ll res = 0;

  for (ll i = 2; i * i <= m; i++) {
    ll cost = 0;

    while (n % i == 0 and n > 1) {
      cost++;
      n = n / i;
    }

    int temp = 0, j = 1;
    while (cost - j >= 0) {
      cost = cost - j;
      temp++;
      j++;
    }
    res += temp;
  }

  if (n > 1)
    res++;
  cout << res;
}

Error: TLE

Fixed submission:

using namespace std;
#include <bits/stdc++.h>
#include <iostream>
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MAX 1000000
void abc() {
  FIO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void sieve(vector<int> &prime) {
  for (int i = 2; i * i <= MAX; i++) {
    if (prime[i] == 1) {
      for (int j = i * i; j < MAX; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  abc();

  int n;
  cin >> n;
  int m = n;

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

  int res = 0;

  for (int i = 2; i * i <= m; i++) {
    int cost = 0;

    while (n % i == 0 and n > 1) {
      cost++;
      n = n / i;
    }

    int temp = 0, j = 1;
    while (cost - j >= 0) {
      cost = cost - j;
      temp++;
      j++;
    }
    res += temp;
  }

  if (n != 1)
    cout << 1;
  else
    cout << res;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define ABS(a) (a < 0 ? -a : a)
#define YesNo(flag) (flag ? "Yes\\n" : "No\\n")
#define YESNO(flag) (flag ? "YES\\n" : "NO\\n")

constexpr auto NMAX = (int)1e2 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
using namespace std;

typedef unsigned long long ull;

bool isPrime(ull n) {
  if (n < 2) {
    return false;
  }
  if (n == 2) {
    return true;
  }
  if (n % 2 == 0) {
    return false;
  }
  for (ull i = 3; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

ull n;
int k;
int sum;

int findN(int k) {
  int n = 0;
  while (n * (n + 1) / 2 < k) {
    n++;
  }
  if (n * (n + 1) / 2 > k) {
    return n - 1;
  }
  return n;
}

int main() {
  cin >> n;

  if (isPrime(n)) {
    cout << 1 << '\\n';
    exit(0);
  }

  while (n % 2 == 0) {
    n >>= 1;
    k++;
  }
  sum += findN(k);
  k = 0;
  for (ull i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      k++;
      n /= i;
    }
    sum += findN(k);
    k = 0;
  }
  if (n != 1) {
    sum++;
  }
  cout << sum << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define ABS(a) (a < 0 ? -a : a)
#define YesNo(flag) (flag ? "Yes\\n" : "No\\n")
#define YESNO(flag) (flag ? "YES\\n" : "NO\\n")

constexpr auto NMAX = (int)1e2 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
using namespace std;

typedef unsigned long long ull;

bool isPrime(ull n) {
  if (n < 2) {
    return false;
  }
  if (n == 2) {
    return true;
  }
  if (n % 2 == 0) {
    return false;
  }
  for (ull i = 3; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

ull n;
int k;
int sum;

int findN(int k) {
  int n = 0;
  while (n * (n + 1) / 2 < k) {
    n++;
  }
  if (n * (n + 1) / 2 > k) {
    return n - 1;
  }
  return n;
}

int main() {
  cin >> n;

  if (isPrime(n)) {
    cout << 1 << '\\n';
    exit(0);
  }

  while (n % 2 == 0) {
    n >>= 1;
    k++;
  }
  sum += findN(k);
  k = 0;
  for (ull i = 3; i <= n; i += 2) {
    while (n % i == 0) {
      k++;
      n /= i;
    }
    sum += findN(k);
    k = 0;
  }
  cout << sum << '\\n';
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

const long long MAXN = 2e6;

int main() {
  long long n;
  cin >> n;
  vector<long long> pr, lp(MAXN);
  for (long long i = 2; i < MAXN; i++) {
    if (!lp[i])
      pr.push_back(i), lp[i] = i;
    for (long long j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN;
         j++)
      lp[pr[j] * i] = pr[j];
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  vector<pair<long long, long long>> factorization;
  long long i = 2;
  while (n != 1) {
    long long d;
    if (n >= MAXN) {
      d = n;
      for (; i * i <= n; i++)
        if (n % i == 0) {
          d = i;
          break;
        }
    } else
      d = lp[n];
    factorization.push_back({d, 0});
    while (n % d == 0) {
      factorization.back().second++;
      n /= d;
    }
  }
  vector<long long> a;
  for (long long i = 0; i < factorization.size(); i++)
    a.push_back(factorization[i].second);
  long long ans = 0;
  for (auto &now : a)
    for (long long x = 0, sum = 0; sum <= now; sum += ++x, ++ans)
      ;
  cout << ans - a.size();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

const long long MAXN = 2e6;

int main() {
  long long n;
  cin >> n;
  vector<int> pr, lp(MAXN);
  for (int i = 2; i < MAXN; i++) {
    if (!lp[i])
      pr.push_back(i), lp[i] = i;
    for (int j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN; j++)
      lp[pr[j] * i] = pr[j];
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  vector<pair<int, int>> factorization;
  long long i = 2;
  while (n != 1) {
    int d;
    if (n >= MAXN) {
      d = n;
      for (; i * i <= n; i++)
        if (n % i == 0) {
          d = i;
          break;
        }
    } else
      d = lp[n];
    factorization.emplace_back(d, 0);
    while (n % d == 0) {
      factorization.back().second++;
      n /= d;
    }
  }
  vector<int> a;
  for (int i = 0; i < factorization.size(); i++)
    a.push_back(factorization[i].second);
  int ans = 0;
  for (auto &now : a)
    for (int x = 0, sum = 0; sum <= now; sum += ++x, ++ans)
      ;
  cout << ans - a.size();
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

vector<pair<int, int>> aaa(0);
int main() {
  cin >> N;

  for (ll i = (2); i * i <= N; i++) {
    if (N % i != 0)
      continue;
    B = 0;

    while (N % i == 0) {
      N /= i;
      B++;
    }
    if (B != 0)
      aaa.push_back(pair<int, int>(i, B));
  }
  if (N != 1)
    aaa.push_back(pair<int, int>(N, 1));

  int sum;
  rep(i, aaa.size()) {
    sum = 0;

    E = aaa[i].second;
    rep2(i, 1, 20) {
      if (E >= i) {
        E -= i;
        sum++;
      } else {
        break;
      }
    }
    D += sum;
  }

  cout << D;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

vector<pair<int, int>> aaa(0);
int main() {
  cin >> N;

  int j = 2;
  B = 0;

  while (N % j == 0) {
    N /= j;
    B++;
  }
  if (B != 0)
    aaa.push_back(pair<int, int>(j, B));

  for (ll i = (3); i < (ll)(1100000000); i += 2) {
    if (N == 1)
      break;
    B = 0;

    while (N % i == 0) {
      N /= i;
      B++;
    }
    if (B != 0)
      aaa.push_back(pair<int, int>(i, B));
  }

  int sum;
  rep(i, aaa.size()) {
    sum = 0;

    E = aaa[i].second;
    rep2(i, 1, 20) {
      if (E >= i) {
        E -= i;
        sum++;
      } else {
        break;
      }
    }
    D += sum;
  }

  cout << D;

  return 0;
}
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<ll, ll>;

vector<P> Div(ll n) {
  vector<P> d;
  for (ll i = 2; i * i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    d.push_back(P(i, cnt));
  }
  if (n != 1)
    d.push_back(P(n, 1));
  return d;
}

int main(void) {
  ll n;
  cin >> n;
  vector<P> d = Div(n);
  ll ans = 0;
  for (ll i = 0; i < d.size(); i++) {
    for (ll j = 1; j <= d[i].second; j++) {
      ll tmp = pow(d[i].first, j);
      if (n % tmp != 0)
        continue;
      n /= tmp;
      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<ll, ll>;

vector<P> Div(ll n) {
  vector<P> d;
  for (int i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    d.push_back(P(i, cnt));
  }
  if (n != 1)
    d.push_back(P(n, 1));
  return d;
}

int main(void) {
  ll n;
  cin >> n;
  vector<P> d = Div(n);
  int ans = 0;
  for (int i = 0; i < d.size(); i++) {
    for (int j = 1; j <= d[i].second; j++) {
      ll tmp = pow(d[i].first, j);
      if (n % tmp != 0)
        continue;
      n /= tmp;
      ans++;

      if (n < tmp)
        break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= N; i++) {
    if (N % i != 0)
      continue;

    ll cnt = 0;
    while (N % i == 0) {
      N /= i;
      cnt++;
    }
    res.push_back(make_pair(i, cnt));
  }

  if (N != 1) {
    res.push_back(make_pair(N, 1));
  }
  return res;
}

int main(void) {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> res = prime_factorize(N);

  ll cnt = 0;
  for (int i = 0; i < res.size(); i++) {
    for (int j = 1; j <= res.at(i).second; j++) {

      ll tmp = pow(res.at(i).first, j);
      if (N % tmp == 0) {
        N /= tmp;
        cnt++;
      }

      if (N < tmp)
        break;
    }
  }
  cout << cnt << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (int i = 2; i * i <= N; i++) {
    if (N % i != 0)
      continue;

    ll cnt = 0;
    while (N % i == 0) {
      N /= i;
      cnt++;
    }
    res.push_back(make_pair(i, cnt));
  }

  if (N != 1) {
    res.push_back(make_pair(N, 1));
  }
  return res;
}

int main(void) {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> res = prime_factorize(N);

  ll cnt = 0;
  for (int i = 0; i < res.size(); i++) {
    for (int j = 1; j <= res.at(i).second; j++) {

      ll tmp = pow(res.at(i).first, j);
      if (N % tmp == 0) {
        N /= tmp;
        cnt++;
      }

      if (N < tmp)
        break;
    }
  }
  cout << cnt << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = 1e18;

int main() {
  ll n;
  cin >> n;
  vector<ll> p(1000001, 0), q;

  for (ll i = 2; i <= 1000000; i++) {
    if (p[i] == 0) {
      q.push_back(i);
      for (ll j = i; j <= 1000000; j += i) {
        p[j] = 1;
      }
    }
  }
  vector<pll> ans;
  ll sum = 0;
  for (auto x : q) {
    if (n % x == 0) {
      ll cnt = 0;
      while (n % x == 0) {
        cnt++;
        n /= x;
      }
      ans.push_back(make_pair(x, cnt));
    }
  }
  if (n != 1) {
    ans.push_back(make_pair(n, 1));
  }
  for (auto x : ans) {
    ll i = 1;
    while (x.se - i >= 0) {
      sum++;
      x.se -= i;
      i++;
    }
  }
  cout << sum << endl;
  return 0;
}

Error: -11

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = 1e18;

int main() {
  ll n;
  cin >> n;
  vector<ll> p(1000001, 0), q;

  for (ll i = 2; i <= 20000000; i++) {
    if (p[i] == 0) {
      q.push_back(i);
      for (ll j = i; j <= 20000000; j += i) {
        p[j] = 1;
      }
    }
  }
  vector<pll> ans;
  ll sum = 0;
  for (auto x : q) {
    if (n % x == 0) {
      ll cnt = 0;
      while (n % x == 0) {
        cnt++;
        n /= x;
      }
      ans.push_back(make_pair(x, cnt));
    }
  }
  ans.push_back(make_pair(n, 1));
  for (auto x : ans) {
    ll i = 1;
    while (x.se - i >= 0) {
      sum++;
      x.se -= i;
      i++;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  long long N;
  cin >> N;
  int numCount = 0;
  for (int i = 2; (long long)i * i <= N; i++) {
    if (N % i == 0) {
      int times = 0;
      while (N % i == 0) {
        N /= i;
        times++;
      }

      for (int j = 1; j <= times; j++) {
        times -= j;
        numCount++;
      }
    }
  }

  if (N > 1) {
    numCount++;
  }

  cout << numCount << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

bool candidate[1000010];
bool used[1000010];

bool isPrime(long long p) {
  if (p == 2)
    return true;

  if (p % 2 == 0)
    return false;
  for (long long i = 3; i * i < p; i += 2) {
    if (p % i == 0)
      return false;
  }

  return true;
}

int main() {

  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);

  long long N;
  cin >> N;
  for (int i = 2; i <= N / i; i *= 2) {
    candidate[i] = true;
  }

  for (int i = 3; i <= N / i; i += 2) {
    if (!candidate[i]) {
      for (long long j = i; j <= N / j; j *= i) {
        candidate[j] = true;
      }
    }
  }
  long long num = N;
  long long lastDiv;
  int count = 0;
  for (int i = 2; i <= N / i; i++) {
    if (candidate[i]) {
      if (num % i == 0) {
        used[i] = true;
        // cout<<"candidate -> "<<i<< endl;
        num /= i;
        lastDiv = i;
        count++;
        // cout << "Num: " << num <<  " Count: " << count << endl;
      }
    }

    if (num == 1) {
      break;
    }
  }
  if (num > 1) {
    if (!used[num]) {
      bool prime = isPrime(num);
      if (prime)
        count++;
    }
  }
  cout << count << endl;
  ;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll N;
  cin >> N;
  ll res = 0;
  if (N >= 2) {
    for (ll i = 2; i * i <= N; i++) {
      ll z = i;
      while (N % z == 0) {
        N /= z;
        z *= i;
        res++;
      }
      while (N % i == 0)
        N /= i;
    }
    if (N > 1)
      res++;
  }
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

map<ll, ll> primeFact(ll n) {
  map<ll, ll> mp;
  if (n == 1)
    return mp;
  for (ll i = 2; i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    if (cnt > 0) {
      mp.insert(make_pair(i, cnt));
    }
  }
  return mp;
}

int main() {
  ll N;
  cin >> N;
  map<ll, ll> mp = primeFact(N);
  ll res = 0;
  if (!mp.empty()) {
    for (auto p : mp) {
      ll e = p.second;
      ll i = 1;
      while (e >= i) {
        e -= i;
        i++;
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}
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 < n; i++)

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

  int ans = 0;

  for (long long i = 2; i * i <= n; i++) {
    int e = 0;
    while (n % i == 0) {
      n /= i;
      e++;
    }
    int a = 1;
    while ((e - a) >= 0) {
      e -= a;
      a++;
      ans++;
    }
  }
  if (n != 1) {
    ans++;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  int ans = 0;

  for (int i = 2; i * i <= n; i++) {
    int e = 0;
    while (n % i == 0) {
      n /= i;
      e++;
    }
    int a = 1;
    while ((e - a) >= 0) {
      e -= a;
      a++;
      ans++;
    }
  }
  if (n != 1) {
    ans++;
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  vector<int> prm(1);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        prm.back()++;
        n /= i;
      }
      prm.push_back(0);
    }
  }
  if (n > 1ll)
    prm.back()++;
  ll cnt = 0;
  for (int x : prm) {
    int prev = 0;
    for (int i = 1; i <= x; i++) {
      if (i * (i + 1) / 2 <= x)
        prev = i;
      else
        break;
    }
    cnt += prev;
  }
  cout << cnt;
}

Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  vector<int> prm(1);
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        prm.back()++;
        n /= i;
      }
      prm.push_back(0);
    }
  }
  if (n > 1ll)
    prm.back()++;
  ll cnt = 0;
  for (int x : prm) {
    int prev = 0;
    for (int i = 1; i <= x; i++) {
      if (i * (i + 1) / 2 <= x)
        prev = i;
      else
        break;
    }
    cnt += prev;
  }
  cout << cnt;
}