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

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

#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll>> // vvl data(10, vector<ll>(10);
#define fo(i, a, b) for (ll i = a; i < b; i++)

vl prime_factorize(ll N) {
  vl res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    ll ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      res.push_back(a);
      N /= a;
    }
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back(N);
  return res;
}

vl findFactors(ll num) {
  vl factors;
  ll i;
  while (num % 2 == 0) { // 偶数の素数は2のみ
    factors.push_back(2);
    num /= 2;
  }
  for (i = 3; i <= num; i++) { // 他の素数で割っていく
    while (num % i == 0) {
      factors.push_back(i);
      num /= i;
    }
  }

  return factors;
}

int main() {
  ll N;
  cin >> N;
  vl factors = prime_factorize(N);

  // fo(i, 0, factors.size()){
  //     cout << factors[i] << endl;
  // }

  ll ans = 0;
  ll count, border, next;
  fo(i, 0, factors.size()) {
    if ((i == 0) || (factors[i] != factors[i - 1])) {
      ans++;
      count = 1;
      border = 3;
      next = 3;
    } else {
      count++;
      if (count == border) {
        ans++;
        border += next;
        next++;
      }
    }
  }

  cout << ans << endl;
}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

Error: TLE

Fixed submission:

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

#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll>> // vvl data(10, vector<ll>(10);
#define fo(i, a, b) for (ll i = a; i < b; i++)

vl findFactors(ll num) {
  vl factors;
  ll i;
  while (num % 2 == 0) { // 偶数の素数は2のみ
    factors.push_back(2);
    num /= 2;
  }
  for (i = 3; i <= num; i++) { // 他の素数で割っていく
    while (num % i == 0) {
      factors.push_back(i);
      num /= i;
    }
  }

  return factors;
}

int main() {
  ll N;
  cin >> N;
  vl factors = findFactors(N);

  // fo(i, 0, factors.size()){
  //     cout << factors[i] << endl;
  // }

  ll ans = 0;
  ll count, border, next;
  fo(i, 0, factors.size()) {
    if ((i == 0) || (factors[i] != factors[i - 1])) {
      ans++;
      count = 1;
      border = 3;
      next = 3;
    } else {
      count++;
      if (count == border) {
        ans++;
        border += next;
        next++;
      }
    }
  }

  cout << ans << endl;
}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n;
  int ans = 0;
  cin >> n;

  vector<int> fact(0); // factor container
  long long num = n;   // 素因数分解する変数num
  bool chk = true;

  for (int i = 2; i < sqrt(n); i++) {
    chk = true;
    while (num % i == 0) { // 素数で割り切れなくなるまで割っていく
      if (chk)
        fact.push_back(0);
      fact.back()++; // 割った個数を配列に足す
      num /= i;
      chk = false;
    }
  }

  if (num > sqrt(n))
    fact.push_back(1);

  for (int i = 0; i < fact.size(); i++) {
    int j = 1;
    while (fact.at(i) >= 0) {
      fact.at(i) -= j;
      if (fact.at(i) < 0)
        break;
      ans++;
      j++;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long n;
  int ans = 0;
  cin >> n;

  vector<int> fact(0); // factor container
  long long num = n;   // 素因数分解する変数num
  bool chk = true;

  for (int i = 2; i <= num; i++) {
    chk = true;
    while (num % i == 0) { // 素数で割り切れなくなるまで割っていく
      if (chk)
        fact.push_back(0);
      fact.back()++; // 割った個数を配列に足す
      num /= i;
      chk = false;
    }
  }

  for (int i = 0; i < fact.size(); i++) {
    int j = 1;
    while (fact.at(i) >= 0) {
      fact.at(i) -= j;
      if (fact.at(i) < 0)
        break;
      ans++;
      j++;
    }
  }

  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;
  vector<int> fc;
  for (long long i = 2; i * i < N; i++) {
    if (N % i == 0) {
      int cnt = 0;
      while (N % i == 0) {
        cnt++;
        N /= i;
      }
      fc.push_back(cnt);
    }
  }
  if (N != 1) {
    fc.push_back(1);
  }
  int M = fc.size();
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int t = 0;
    int f = 10000;
    while (f - t > 1) {
      int m = (f + t) / 2;
      if (m * (m + 1) / 2 <= fc[i]) {
        t = m;
      } else {
        f = m;
      }
    }
    ans += t;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<int> fc;
  for (int i = 2; i * i < N; i++) {
    if (N % i == 0) {
      int cnt = 0;
      while (N % i == 0) {
        cnt++;
        N /= i;
      }
      fc.push_back(cnt);
    }
  }
  if (N != 1) {
    fc.push_back(1);
  }
  int M = fc.size();
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int t = 0;
    int f = 10000;
    while (f - t > 1) {
      int m = (f + t) / 2;
      if (m * (m + 1) / 2 <= fc[i]) {
        t = m;
      } else {
        f = m;
      }
    }
    ans += t;
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int solve(long long n) {
  if (n == 1) {
    return 0;
  }
  vector<long long> f;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      f.push_back(i);
      n /= i;
    }
  }
  if (n > 1)
    f.push_back(n);

  int ans = 0;
  int i = 0;
  while (i < f.size()) {
    int j = i + 1;
    while (j < f.size() && f.at(j) == f.at(i))
      j++;
    int count = j - i;
    i = j;
    int sum = 0;
    for (int x = 1; count >= sum + x; x++, ans++)
      sum += x;
  }
  return ans;
}

int main() {
  long long n;
  cin >> n;
  cout << solve(n) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int solve(long long n) {
  if (n == 1) {
    return 0;
  }
  vector<int> f;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      f.push_back(i);
      n /= i;
    }
  }
  if (n > 1)
    f.push_back(n);

  int ans = 0;
  int i = 0;
  while (i < f.size()) {
    int j = i + 1;
    while (j < f.size() && f.at(j) == f.at(i))
      j++;
    int count = j - i;
    i = j;
    int sum = 0;
    for (int x = 1; count >= sum + x; x++, ans++)
      sum += x;
  }
  return ans;
}

int main() {
  long long n;
  cin >> n;
  cout << solve(n) << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll n;
  cin >> n;
  ll sq = sqrt(n) + 1;
  ll ans = 0;
  for (int i = 2; i <= sq; i++) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    ll cur = 1;
    while (cnt > 0) {
      if (cnt - cur >= 0) {
        ans++;
      }
      cnt -= cur;
      cur++;
    }
  }
  if (n > 1) {
    ans++;
  }
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll n;
  cin >> n;
  ll sq = sqrt(n) + 1;
  ll ans = 0;
  for (int i = 2; i <= sq; i++) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    ll cur = 1;
    while (cnt > 0) {
      if (cnt - cur >= 0) {
        ans++;
        cnt -= cur;
        cur++;
      }
    }
  }
  if (n > 1) {
    ans++;
  }
  cout << ans << "\\n";
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll mod = 1e9 + 0LL;
ll MOD = 1e18 + 0LL;
double pi = acos(-1);

int main() {
  int cs = 1;
  // scanf("%d",&cs);
  while (cs--) {
    ll n;
    int i, j;
    ll ans = 0;
    cin >> n;
    for (i = 2; i <= 1000010; i++) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      if (!cnt)
        continue;
      for (j = 1; j <= 100; j++) {
        if (cnt < j)
          break;
        ans++;
        cnt -= j;
      }
    }
    if (n > 1)
      ans++;
    cout << ans << "\\n";
  }
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll mod = 1e9 + 0LL;
ll MOD = 1e18 + 0LL;
double pi = acos(-1);

int main() {
  int cs = 1;
  // scanf("%d",&cs);
  while (cs--) {
    ll n;
    int i, j;
    ll ans = 0;
    cin >> n;
    for (i = 2; i * i <= n; i++) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      if (!cnt)
        continue;
      for (j = 1; j <= 100; j++) {
        if (cnt < j)
          break;
        ans++;
        cnt -= j;
      }
    }
    if (n > 1)
      ans++;
    cout << ans << "\\n";
  }
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define ull unsigned ll

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define INFLL 9e18
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp emplace_back
#define PI acos(-1.0)
#define endl "\\n"
#define mp make_pair
#define DEBUG 0

int main()

{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout.tie(NULL);

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

  long long n;
  cin >> n;

  ll count = 0;
  ll ans = 0;
  bool isPrime = true;
  if (n == 1)
    isPrime = false;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      isPrime = false;
      while (n % i == 0) {
        n /= i;
        count++;
      }
      double now = -0.5 + 0.5 * (sqrt(1.0 + 8.0 * (double)count));
      // cout << i << " " << count << " " << now << endl;
      ans += (long long)now;
      count = 0;
      now = 0.0;
    }
  }
  if (n > 1)
    ans += 1;
  if (!isPrime)
    cout << ans << endl;
  else
    cout << 1 << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define ull unsigned ll

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define INFLL 9e18
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp emplace_back
#define PI acos(-1.0)
#define endl "\\n"
#define mp make_pair
#define DEBUG 0

int main()

{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout.tie(NULL);

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

  long long n;
  cin >> n;

  ll count = 0;
  ll ans = 0;
  bool isPrime = true;
  if (n == 1)
    isPrime = false;

  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      isPrime = false;
      while (n % i == 0) {
        n /= i;
        count++;
      }
      double now = -0.5 + 0.5 * (sqrt(1.0 + 8.0 * (double)count));
      // cout << i << " " << count << " " << now << endl;
      ans += (long long)now;
      count = 0;
      now = 0.0;
    }
  }
  if (n > 1)
    ans += 1;
  if (!isPrime)
    cout << ans << endl;
  else
    cout << 1 << endl;

  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IO                                                                     \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mset(s, _) memset(s, _, sizeof s)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mk make_pair
using namespace std;
const int maxn = 1000010;
ll vp[maxn + 10], p[maxn + 10];
void prime() {
  vp[0] = vp[1] = 1; // 0和1为合数
  for (ll i = 2; i < maxn; i++) {
    if (!vp[i])
      p[++p[0]] = i; // p[]里面的是素数
    for (ll j = 1; j <= p[0] && i * p[j] < maxn; j++) {
      vp[i * p[j]] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
vector<ll> v;
void init() {
  for (ll i = 1; i <= p[0]; i++) {
    for (ll j = p[i]; j <= 1000000000000; j *= p[i]) {
      v.push_back(j);
    }
  }
}
int main() {
  prime();
  init();
  ll n;
  sort(v.begin(), v.end());
  while (cin >> n) {
    int ans = 0, w1 = 0;
    for (int i = 0; i < v.size(); i++) {
      if (n % v[i] == 0)
        n /= v[i], ans++, vp[v[i]] = 1;
      if (n < v[i])
        break;
    }
    if (n > 1000000)
      cout << ans + 1 << '\\n';
    else
      cout << ans << '\\n';
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IO                                                                     \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mset(s, _) memset(s, _, sizeof s)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mk make_pair
using namespace std;
const int maxn = 1000010;
ll vp[maxn + 10], p[maxn + 10];
void prime() {
  vp[0] = vp[1] = 1; // 0和1为合数
  for (ll i = 2; i < maxn; i++) {
    if (!vp[i])
      p[++p[0]] = i; // p[]里面的是素数
    for (ll j = 1; j <= p[0] && i * p[j] < maxn; j++) {
      vp[i * p[j]] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
vector<ll> v;
void init() {
  for (ll i = 1; i <= p[0]; i++) {
    for (ll j = p[i]; j <= maxn; j *= p[i]) {
      v.push_back(j);
    }
  }
}

int main() {
  prime();
  init();
  ll n;
  sort(v.begin(), v.end());
  cin >> n;
  int ans = 0, w1 = 0;
  for (int i = 0; i < v.size(); i++) {
    if (n % v[i] == 0)
      n /= v[i], ans++, vp[v[i]] = 1, w1 = 1;
    if (n < v[i])
      break;
  }

  if ((!w1 || !vp[n]))
    ans++;
  cout << ans << '\\n';
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define vl vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：
// 問題文URL：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
ll n;

vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ans;
  ll index = -1;
  for (ll i = 2; i <= n; i++) {
    if (i > sqrt(n)) {
      ans.push_back(make_pair(n, 1));
      break;
    }
    if (n % i == 0) {
      ans.push_back(make_pair(i, 0));
      index++;
    }
    while (n % i == 0) {
      n /= i;
      ans[index].second++;
    }
  }
  return ans;
}

void solve() {
  vector<pair<ll, ll>> a = primeFac(n);
  ll ans = 0;
  rep(i, a.size()) {
    ll index = a[i].second;
    ll m = 0;
    while (index >= (m + 1) * (m + 2) / 2) {
      m++;
    }
    ans += m;
    // cout << "底:" << a[i].first << " 指数:" << index << " m:" << m << endl;
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define vl vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：
// 問題文URL：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
ll n;

vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ans;
  ll index = -1;
  for (ll i = 2; i <= n; i++) {
    if (index == -1 && i > sqrt(n)) {
      ans.push_back(make_pair(n, 1));
      break;
    }
    if (n % i == 0) {
      ans.push_back(make_pair(i, 0));
      index++;
    }
    while (n % i == 0) {
      n /= i;
      ans[index].second++;
    }
  }
  return ans;
}

void solve() {
  vector<pair<ll, ll>> a = primeFac(n);
  ll ans = 0;
  rep(i, a.size()) {
    ll index = a[i].second;
    ll m = 0;
    while (index >= (m + 1) * (m + 2) / 2) {
      m++;
    }
    ans += m;
    // cout << "底:" << a[i].first << " 指数:" << index << " m:" << m << endl;
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  solve();
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

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

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;
}


Error: WA

Fixed submission:

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

long long int limit = 1000000000000000000;

int main() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  long long int total = 1;

  for (int i = 0; i < n; i++) {
    total *= a.at(i);
    if (total > limit) {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << fixed << setprecision(20) << total << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

// 素因数分解

#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

int main(void) {
  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: 0

Fixed submission:

// エラトステネスの篩　素因数分解

#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

// 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(void) {
  int N;
  cin >> N;

  Sieve s(1000005);
  auto fs = s.factor(N);

  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;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> 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 main() {
  ll n, ans = 0;
  cin >> n;
  for (auto x : prime_factor(n)) {
    ll now = x.second, i = 1;
    while (now - i >= 0) {
      now -= i;
      ans++;
      i++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> ma;
  rep(i, 15) { rep(j, i) ma.push_back(i); }
  for (int i = 2; i * i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt == 0)
      continue;
    ans += ma[cnt] - 1;
  }
  if (n != 1)
    ans++;
  cout << ans << endl;
}