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

#include <iostream>
#include <math.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  int counter = 0;
  int shisuu = 0;
  int a = 2;

  while (N % 2 == 0) {
    N /= 2;
    shisuu++;
  }

  if (shisuu != 0) {
    /*  cout << a << ' ' << shisuu << endl; */
    int i = 1;
    while (shisuu >= i) {
      shisuu -= i;
      counter++;
      i++;
    }
    shisuu = 0;
  }

  for (a = 3; a <= pow(N, 0.5); a += 2) {
    while (N % a == 0) {
      N /= a;
      shisuu++;
    }

    if (shisuu != 0) {
      //     cout << a << ' ' << shisuu << endl;
      int i = 1;
      while (shisuu >= i) {
        shisuu -= i;
        counter++;
        i++;
      }
      shisuu = 0;
    }
  }

  if (N != 1)
    counter++;

  cout << counter << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  int counter = 0;
  int shisuu = 0;
  int a = 2;

  while (N % 2 == 0) {
    N /= 2;
    shisuu++;
  }

  if (shisuu != 0) {
    /*  cout << a << ' ' << shisuu << endl; */
    int i = 1;
    while (shisuu >= i) {
      shisuu -= i;
      counter++;
      i++;
    }
    shisuu = 0;
  }

  for (a = 3; a <= N; a += 2) {
    while (N % a == 0) {
      N /= a;
      shisuu++;
    }

    if (shisuu != 0) {
      //     cout << a << ' ' << shisuu << endl;
      int i = 1;
      while (shisuu >= i) {
        shisuu -= i;
        counter++;
        i++;
      }
      shisuu = 0;
    }
  }

  cout << counter << endl;

  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define mems(p) memset(p, -1, sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\\n"

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  fast();
  ll n;
  cin >> n;
  ll lastI;
  ll res = 0;
  for (ll i = 2; i * i <= n; ++i) {
    // cout << "pi";
    int tot = 0;
    while (n % i == 0) {
      // cout << "po";
      n /= i;
      ++tot;
    }
    if (tot > 0) {
      ll lb = 1, rb = 44;
      while (lb < rb) {
        // cout << "pe";
        ll mb = (lb + rb + 1) / 2;
        ll val = mb * (mb + 1) / 2;
        if (val == tot) {
          lb = mb;
          rb = mb;
        } else if (val < tot) {
          lb = mb;
        } else {
          rb = mb - 1;
        }
      }
      res += lb;
    }
    lastI = i;
  }
  if (n > 1) {
    ++res;
  }
  cout << res << nl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define mems(p) memset(p, -1, sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\\n"

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  fast();
  ll n;
  cin >> n;
  ll copyN = n;
  ll lastI;
  ll res = 0;
  for (int i = 2; i * i <= n; ++i) {
    // cout << "pi";
    int tot = 0;
    while (n % i == 0) {
      // cout << "po";
      n /= i;
      ++tot;
    }
    if (tot > 0) {
      ll lb = 1, rb = 44;
      while (lb < rb) {
        // cout << "pe";
        ll mb = (lb + rb + 1) / 2;
        ll val = mb * (mb + 1) / 2;
        if (val == tot) {
          lb = mb;
          rb = mb;
        } else if (val < tot) {
          lb = mb;
        } else {
          rb = mb - 1;
        }
      }
      res += lb;
    }
    lastI = i;
  }
  if (n > 1) {
    ++res;
  }
  cout << res << nl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

/// first: primo   second: exponente
vector<pair<ll, ll>> Canon;
int Gau[50];

void Prec() {

  int i;

  for (i = 1; i < 50; i++) {
    Gau[i] = Gau[i - 1] + i;
  }

  return;
}

int main() {

  ll N, Aux;
  cin >> N;
  ll i, j;

  Aux = N;

  if (Aux % 2 == 0) {
    Aux /= 2;
    Canon.push_back({2, 1});
    while (Aux % 2 == 0) {
      Aux /= 2;
      Canon[Canon.size() - 1].second += 1;
    }
  }

  if (Aux % 3 == 0) {
    Aux /= 3;
    Canon.push_back({3, 1});
    while (Aux % 3 == 0) {
      Aux /= 3;
      Canon[Canon.size() - 1].second += 1;
    }
  }

  if (Aux % 5 == 0) {
    Aux /= 5;
    Canon.push_back({5, 1});
    while (Aux % 5 == 0) {
      Aux /= 5;
      Canon[Canon.size() - 1].second += 1;
    }
  }

  for (i = 6; i * i <= Aux; i += 6) {

    if (Aux % (i + 1) == 0) {
      Aux /= (i + 1);
      Canon.push_back({i + 1, 1});
      while (Aux % (i + 1) == 0) {
        Aux /= (i + 1);
        Canon[Canon.size() - 1].second += 1;
      }
    }

    if (Aux % (i + 5) == 0) {
      Aux /= (i + 5);
      Canon.push_back({i + 5, 1});
      while (Aux % (i + 5) == 0) {
        Aux /= (i + 5);
        Canon[Canon.size() - 1].second += 1;
      }
    }
  }

  if (Aux > 1)
    Canon.push_back({Aux, 1});
  Prec();

  int Ans = 0;

  for (i = 0; i < Canon.size(); i++) {
    j = 1;
    while (Canon[i].second >= Gau[j])
      j += 1;
    Ans += j - 1;
  }

  cout << Ans;
}


Error: TLE

Fixed submission:

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

/// first: primo   second: exponente
vector<pair<ll, ll>> Canon;
int Gau[50];

void Prec() {

  int i;

  for (i = 1; i < 50; i++) {
    Gau[i] = Gau[i - 1] + i;
  }

  return;
}

int main() {

  ll N, Aux;
  cin >> N;
  int i, j;

  Aux = N;

  if (Aux % 2 == 0) {
    Aux /= 2;
    Canon.push_back({2, 1});
    while (Aux % 2 == 0) {
      Aux /= 2;
      Canon[Canon.size() - 1].second += 1;
    }
  }

  if (Aux % 3 == 0) {
    Aux /= 3;
    Canon.push_back({3, 1});
    while (Aux % 3 == 0) {
      Aux /= 3;
      Canon[Canon.size() - 1].second += 1;
    }
  }

  if (Aux % 5 == 0) {
    Aux /= 5;
    Canon.push_back({5, 1});
    while (Aux % 5 == 0) {
      Aux /= 5;
      Canon[Canon.size() - 1].second += 1;
    }
  }

  for (i = 6; i * i <= Aux; i += 6) {

    if (Aux % (i + 1) == 0) {
      Aux /= (i + 1);
      Canon.push_back({i + 1, 1});
      while (Aux % (i + 1) == 0) {
        Aux /= (i + 1);
        Canon[Canon.size() - 1].second += 1;
      }
    }

    if (Aux % (i + 5) == 0) {
      Aux /= (i + 5);
      Canon.push_back({i + 5, 1});
      while (Aux % (i + 5) == 0) {
        Aux /= (i + 5);
        Canon[Canon.size() - 1].second += 1;
      }
    }
  }

  if (Aux > 1)
    Canon.push_back({Aux, 1});
  Prec();

  int Ans = 0;

  for (i = 0; i < Canon.size(); i++) {
    j = 1;
    while (Canon[i].second >= Gau[j])
      j += 1;
    Ans += j - 1;
  }

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

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

int main() {
  long long n;
  cin >> n;
  if (n == 1) {
    cout << "0";
    return 0;
  }
  long long a, count = 0, i;
  a = sqrt(n) + 1;
  map<int, int> mp;
  for (i = 2; i <= a; i++) {
    while (n % i == 0) {
      n /= i;
      mp[i]++;
      a = sqrt(n) + 1;
    }
  }
  if (n != 1) {
    mp[n]++;
  }
  // for(auto a:mp){
  //     cout<<a.first<<" "<<a.second<<endl;
  // }
  int ans = 0;
  for (auto a : mp) {
    for (int i = 1; a.second - i >= 0; i++) {
      a.second -= i;
      ans++;
    }
  }
  cout << ans;
}


Error: TLE

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  long long a, count = 0;
  a = n / 2 + 1;
  for (int i = 2; i <= a; i++) {
    // cout<<n<<" "<<a<<endl;
    if (n % i == 0) {
      n /= i;
      count++;
    }
  }
  if (n > 1LL && count == 0LL)
    cout << "1";
  else
    cout << count;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
ll N;

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int calc(int x) {
  if (x <= 2)
    return 1;
  int a = 0;
  while (a * (a + 1) / 2 <= x) {
    a++;
  }
  return a - 1;
}

int main() {
  INCANT;
  cin >> N;
  map<ll, int> ret = prime_factor(N);
  int ans = 0;
  for (auto p : ret)
    ans += calc(p.second);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT                                                                 \\
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0),                            \\
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7LL;
const int INF = 2e9;
ll N;

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int calc(int x) {
  int a = 0;
  while (a * (a + 1) / 2 <= x) {
    a++;
  }
  return a - 1;
}

int main() {
  INCANT;
  cin >> N;
  map<ll, int> ret = prime_factor(N);
  int ans = 0;
  for (auto p : ret) {
    ans += calc(p.second);
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

template <typename T> void print(const T &v);

vector<pair<ll, ll>> factorization(ll num) {
  map<ll, ll> mp;

  ll tmp = num;
  for (ll i = 2; i * i <= num; i++) {
    while (tmp % i == 0) {
      mp[i]++;
      tmp /= i;
    }
  }
  if (tmp != 1) {
    mp[num]++;
  }
  vector<pair<ll, ll>> ret;
  for (auto m : mp) {
    ret.push_back(make_pair(m.first, m.second));
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  auto fac = factorization(n);
  ll ans = 0;
  for (auto fa : fac) {
    ll cnt = 1;
    while (fa.second >= 0) {
      fa.second -= cnt;
      ans++;
      cnt++;
    }
    ans--;
  }
  cout << ans << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}


Error: TLE

Fixed submission:

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

template <typename T> void print(const T &v);

vector<pair<ll, int>> factorization(ll num) {
  map<ll, int> mp;
  for (int i = 2; i * i <= num; i++) {
    while (num % i == 0) {
      mp[i]++;
      num /= i;
    }
  }
  if (num != 1) {
    mp[num]++;
  }
  vector<pair<ll, int>> ret;
  for (auto m : mp) {
    ret.push_back(make_pair(m.first, m.second));
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  auto fac = factorization(n);
  ll ans = 0;
  for (auto fa : fac) {
    int cnt = 1;
    while (fa.second >= 0) {
      fa.second -= cnt;
      ans++;
      cnt++;
    }
    ans--;
  }
  cout << ans << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}
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 n2 = n;
  ll a = sqrt(n);
  vector<ll> p(a + 1, 0);
  ll ans = 0;
  ll ch = 0;
  for (ll i = 2; i <= a; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        p[ch]++;
        n /= i;
      }
      ch++;
    }
    if (n == 1) {
      break;
    }
  }
  if (n != 1) {
    ans++;
  }
  for (ll i = 0; i <= ch; i++) {
    if (p[i] != 0) {
      int count = 1;
      while (count <= p[i]) {
        p[i] -= count;
        count++;
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  ll n;
  cin >> n;
  ll n2 = n;
  ll a = sqrt(n);
  vector<ll> p(a + 1, 0);
  ll ans = 0;
  ll ch = 0;
  for (ll i = 2; i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        p[ch]++;
        n /= i;
      }
      ch++;
    }
    if (n == 0) {
      break;
    }
  }
  for (ll i = 0; i <= ch; i++) {
    if (p[i] != 0) {
      int count = 1;
      while (count <= p[i]) {
        p[i] -= count;
        count++;
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long N;
  cin >> N;
  int ans = 0;
  int count;
  for (long long i = 2; i * i <= N; i++) {
    count = 0;
    while (N % i == 0) {
      count++;
      N /= i;
    }
    for (int j = 1; count - j >= 0; j++) {
      ans++;
      count -= j;
    }
  }
  if (N > 1)
    ans++;
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  long long a = 1;
  bool sosu = true;
  for (long long i = 2; i <= N; i++) {
    for (int j = 1; j <= 100; j++) {
      a = long(pow(i, j));
      if (N % a == 0) {
        ans++;
        sosu = false;
        N /= a;
      } else
        break;
    }
    while (N % i == 0) {
      N /= i;
    }
  }
  if (sosu && N != 1)
    ans++;
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define m 5000005
typedef long long ll;
vector<ll> prime;
bool sieve[m + 2];
map<ll, ll> mp;
vector<ll> factor;

void primeSieve() {
  memset(sieve, true, sizeof(sieve));

  sieve[0] = sieve[1] = false;

  prime.push_back(2);
  for (int i = 4; i <= m; i += 2)
    sieve[i] = false;

  int sqrtn = sqrt(m);
  for (int i = 3; i <= sqrtn; i += 2) {
    if (sieve[i]) {
      for (ll j = i * i; j <= m; j += 2 * i)
        sieve[j] = false;
    }
  }

  for (int i = 3; i <= m; i += 2)
    if (sieve[i])
      prime.push_back(i);
}

void find(ll n) {
  ll idx = 0, pf = prime[idx];

  while (pf * pf <= n) {
    if (n % pf == 0) {
      factor.push_back(pf);
      while (n % pf == 0) {
        n /= pf;
        mp[pf]++;
      }
    }
    pf = prime[++idx];
  }
  if (n != 1) {
    mp[n]++;
    factor.push_back(n);
  }
}

int main() {
  primeSieve();
  ll n, i, ans, res = 0, k, j = 1;

  cin >> n;
  find(n);

  for (i = 0; i < factor.size(); i++) {
    j = 1;
    ans = mp[factor[i]];
    while (ans >= j) {
      ans -= j;
      res++;
      j++;
    }
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define m 5000005
typedef long long ll;
vector<int> prime;
bool sieve[m + 2];
map<ll, ll> mp;
vector<int> factor;

void primeSieve() {
  memset(sieve, true, sizeof(sieve));

  sieve[0] = sieve[1] = false;

  prime.push_back(2);
  for (int i = 4; i <= m; i += 2)
    sieve[i] = false;

  int sqrtn = sqrt(m);
  for (int i = 3; i <= sqrtn; i += 2) {
    if (sieve[i]) {
      for (ll j = i * i; j <= m; j += 2 * i)
        sieve[j] = false;
    }
  }

  for (int i = 3; i <= m; i += 2)
    if (sieve[i])
      prime.push_back(i);
}

void find(ll n) {
  ll idx = 0, pf = prime[idx];

  while (pf * pf <= n) {
    if (n % pf == 0) {
      factor.push_back(pf);
      while (n % pf == 0) {
        n /= pf;
        mp[pf]++;
      }
    }
    pf = prime[++idx];
  }
  if (n != 1) {
    mp[n]++;
    factor.push_back(n);
  }
}

int main() {
  primeSieve();
  ll n, i, ans, res = 0, j, k;

  cin >> n;
  find(n);

  for (i = 0; i < factor.size(); i++) {
    ans = mp[factor[i]];
    for (j = 1;; j++) {
      ans -= j;
      if (ans == 0) {
        res += j;
        break;
      }
    }
  }
  cout << res << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream> // istringstream
#include <string>
#include <vector>

using namespace std;

int countup(int n) {
  int count = 1;
  while (true) {
    if (n >= count) {
      n -= count;
      count++;
    } else {
      break;
    }
  }
  return count - 1;
}

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

  int memo[1000000 + 10] = {0};
  bool flag1 = true;
  long long N_c = N;
  int ans = 0;
  while (flag1) {
    for (long long i = 2; i <= (int)sqrt(N) + 1; ++i) {
      if (N_c % i == 0) {
        memo[i]++;
        N_c /= i;
        break;
      }
      // 素数がこれ以上見つからない
      if (i >= (int)sqrt(N)) {
        flag1 = false;
      }
    }
  }
  // 1じゃない場合はNそのものが素数の場合
  if (N_c != 1) {
    ans++;
  }
  for (long long i = 2; i <= (int)sqrt(N) + 1; ++i) {
    ans += countup(memo[i]);
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream> // istringstream
#include <string>
#include <vector>

using namespace std;

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

  int memo[100000];
  bool flag1 = true;
  long long N_c = N;
  int ans = 0;
  bool flag3 = false;
  while (flag1) {
    for (int i = 2; i <= (int)sqrt(N) + 1; ++i) {
      // cout << i << " " << (int)sqrt(N)+1 << endl;
      if (N_c % i == 0) {
        memo[i]++;
        N_c /= i;
        break;
      }
      if (i >= (int)sqrt(N)) {
        // 素数がこれ以上見つからない
        if (N_c >= (int)sqrt(N) + 1) {
          flag3 = true;
        }
        flag1 = false;
      }
    }
  }
  if (flag3) {
    ans++;
  }

  for (long long i = 2; i <= (int)sqrt(N) + 1; ++i) {
    bool flag2 = true;
    int count1 = 1;
    int count2 = 2;
    while (flag2) {
      if (memo[i] >= count1) {
        ans++;
        count1 += count2;
        count2++;
      } else {
        flag2 = false;
      }
    }
  }
  cout << ans << endl;

  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)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

template <typename T> map<T, ll> factorize(T x) {
  map<T, ll> res;
  for (ll i = 2; i * i <= x; i++) {
    while (x % i == 0) {
      x /= i;
      res[i]++;
    }
  }
  if (x != 1)
    res[x]++;
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  map<ll, ll> mp = factorize(n);
  ll ans = 0;
  for (auto &c : mp) {
    int k = -1;
    for (int i = 1; i * (i + 1) / 2 <= c.second; ++i) {
      k = i;
    }
    if (k == -1)
      continue;
    ans += k;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

template <typename T> map<T, ll> factorize(T x) {
  map<T, ll> res;
  for (int i = 2; i * i <= x; i++) {
    while (x % i == 0) {
      x /= i;
      res[i]++;
    }
  }
  if (x != 1)
    res[x]++;
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  map<ll, ll> mp = factorize(n);
  ll ans = 0;
  for (auto &c : mp) {
    int k = -1;
    for (int i = 1; i * (i + 1) / 2 <= c.second; ++i) {
      k = i;
    }
    if (k == -1)
      continue;
    ans += k;
  }
  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;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b)
    swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll ex = 0;
    while (n % i == 0) {
      n /= i;
      ex++;
    }
    ret.push_back(make_pair(i, ex));
  }
  if (n != 1)
    ret.push_back(make_pair(n, 1));
  return ret;
}
} // namespace my
////////////////////////

int main() {
  ll n;
  cin >> n;
  auto primes = my::primeFac(n);

  int ans = 0;
  for (auto &primesi : primes) {
    int exp = primesi.second;
    int i = 1;
    while (exp - i >= 0) {
      exp -= i;
      i++;
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b)
    swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
} // namespace my
////////////////////////

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

ll powll(ll a, ll b) {
  ll ret = 1;
  for (ll i = 0; i < b; i++) {
    ret *= a;
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  ll n_origin = n;
  for (ll i = 2; i <= n; i++) {
    if (!isPrime(i))
      continue;
    if (ans == 0 && i * i > n_origin)
      break;
    ll tmp = 1;
    while (n % powll(i, tmp) == 0) {
      n /= powll(i, tmp);
      tmp++;
      ans++;
    }
  }
  if (ans == 0)
    ans = 1;
  cout << ans << endl;
}