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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

vector<pair<long long, int>> factor(long long n) {

  long long m = n;

  vector<pair<long long, int>> res;

  for (long long i = 2; i * i <= m; i++) {

    int x = 0;

    while (n % i == 0) {

      n /= i;
      x++;
    }
    res.emplace_back(i, x);
  }
  if (n != 1)
    res.emplace_back(n, 1);

  return res;
}

long long isprime(long long x) {

  if (x == 2) {
    return true;
  }
  if (x < 2 || x % 2 == 0) {
    return false;
  }

  long long sqrtx = sqrt(x);

  long long i = 3;

  while (i <= sqrtx) {

    if (x % i == 0) {
      return false;
    }

    i += 2;
  }

  return true;
}

int main() {

  ll n;

  cin >> n;

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

  auto fs = factor(n);

  ll ans = 0;

  for (auto p : fs) {
    ll a = p.second;
    ll b = 1;
    while (b <= a) {
      a -= b;
      b++;
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

vector<pair<long long, int>> factor(long long n) {

  long long m = n;

  vector<pair<long long, int>> res;

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

    int x = 0;

    while (n % i == 0) {

      n /= i;
      x++;
    }
    res.emplace_back(i, x);
  }
  if (n != 1)
    res.emplace_back(n, 1);

  return res;
}

int main() {

  ll n;

  cin >> n;

  auto fs = factor(n);

  ll ans = 0;

  for (auto p : fs) {
    ll a = p.second;
    ll b = 1;
    while (b <= a) {
      a -= b;
      b++;
      ans++;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep2(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;
ll MOD = 1000000007;
int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int m = ceil(sqrt(n)) + 1;
  vector<int> index(m);
  rep2(i, 2, m) {
    while (n % i == 0) {
      n /= i;
      index[i]++;
    }
  }
  int ans = 0;
  rep(i, m) {
    rep(j, 45) {
      if (j * (j + 1) / 2 <= index[i] && index[i] < (j + 1) * (j + 2) / 2) {
        ans += j;
        break;
      }
    }
  }
  if (n > 1)
    ans++;
  cout << max(1, ans) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep2(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;
ll MOD = 1000000007;
int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int m = ceil(sqrt(n)) + 10;
  vector<int> index(m);
  rep2(i, 2, m) {
    while (n % i == 0) {
      n /= i;
      index[i]++;
    }
  }
  int ans = 0;
  rep(i, 2 * m) {
    rep(j, 100) {
      if (j * (j + 1) / 2 <= index[i] && index[i] < (j + 1) * (j + 2) / 2) {
        ans += j;
        break;
      }
    }
  }
  cout << max(1, ans) << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  long long sum = 0;
  for (long long i = 2; N > 1 && i * i <= N; i++) {
    long long div = i;
    while (N % div == 0) {
      N /= div;
      div *= i;
      sum++;
    }
    while (N % i == 0) {
      N /= i;
    }
  }
  if (N > 1)
    sum++;

  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  std::map<long long, long long> m;
  for (int i = 2; N > 1 && i * i <= N; i++) {
    while (N % i == 0) {
      m[i]++;
      N /= i;
    }
  }
  if (N > 1)
    m[N]++;

  long long sum = 0;

  for (auto it = m.begin(); it != m.end(); it++) {
    long long count = it->second;
    for (int i = 1; i <= count; i++) {
      sum++;
      count -= i;
    }
  }

  cout << sum << endl;

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

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, ans;
ll f[51];
int prime[1000010], mark[1000010], tot;
ll find(ll x) {
  ll l = 1, r = 1000000, ret = -1;
  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (mid * (mid + 1) / 2 <= x) {
      ret = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ret;
}
void get_prime() {
  for (int i = 2; i <= 1000000; i++) {
    if (!mark[i])
      prime[++tot] = i;
    for (int j = 1; j <= tot; j++) {
      if (prime[j] * i > 1000000)
        break;
      mark[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
int main() {
  get_prime();
  for (int i = 1; i <= 50; i++) {
    f[i] = find(i);
  }
  cin >> n;
  for (int i = 1; prime[i] * prime[i] <= n && i <= tot; i++) {
    if (n % prime[i] == 0) {
      ll cnt = 0;
      while (n % prime[i] == 0) {
        cnt++;
        n /= prime[i];
      }
      ans += f[cnt];
    }
  }
  if (n > 1) {
    ans++;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, ans;
ll f[51];
ll find(ll x) {
  ll l = 1, r = 1000000, ret = -1;
  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (mid * (mid + 1) / 2 <= x) {
      ret = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ret;
}
int main() {
  for (int i = 1; i <= 50; i++) {
    f[i] = find(i);
  }
  cin >> n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      ans += f[cnt];
    }
  }
  if (n > 1) {
    ans++;
  }
  cout << ans;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long sol(long i) {
  long sum = 0;
  long c = 0;
  for (long j = 1;; j++) {
    if (j + sum > i)
      break;
    sum += j;
    c++;
  }
  return c;
}
void solve() {
  long long x;
  cin >> x;
  long long count = 0;
  for (long long i = 2; i <= sqrtl(x); i++) {
    if (x % i == 0) {
      long c = 0;
      while (x % i == 0) {
        x /= i;
        c++;
      }
      count += sol(c);
    }
  }

  if (x > 1)
    count++;
  cout << count;
}

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

  solve();
  return 0;
}


Error: TLE

Fixed submission:

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

long sol(long i) {
  long sum = 0;
  long c = 0;
  for (long j = 1;; j++) {
    if (j + sum > i)
      break;
    sum += j;
    c++;
  }
  return c;
}
void solve() {
  long long x;
  cin >> x;
  long count = 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      int c = 0;
      while (x % i == 0) {
        x /= i;
        c++;
      }
      count += sol(c);
    }
  }

  if (x > 1)
    count++;
  cout << count;
}

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

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

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long int ll;
ll lim[1009];
int main() {
  ll n;
  cin >> n;
  ll cnt = 0, ans = 0;
  for (int i = 1; i <= 1000; i++)
    lim[i] = (i * (i + 1)) / 2;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      cnt = 0;
      while (n % i == 0) {
        n = n / i;
        cnt++;
      }
      ans += upper_bound(lim + 1, lim + 1000, cnt) - lim - 1;
    }
  }
  if (n != 1)
    ans++;
  cout << ans;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long int ll;
ll lim[1009];
int main() {
  ll n;
  cin >> n;
  ll cnt = 0, ans = 0;
  for (int i = 1; i <= 1000; i++)
    lim[i] = (i * (i + 1)) / 2;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      cnt = 0;
      while (n % i == 0) {
        n = n / i;
        cnt++;
      }
      ans += upper_bound(lim + 1, lim + 1000, cnt) - lim - 1;
    }
  }
  if (n != 1)
    ans++;
  cout << ans;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// https://atcoder.jp/contests/abc169/tasks/abc169_c
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll ans = 0;
  ll n;
  cin >> n;
  if (n != 1) {
    ll nn = n;
    ll count = 0;
    for (ll i = 2; i * i <= nn; i++) {
      ll loop = 0;
      while (n % i == 0) {
        n /= i;
        loop++;
      }
      for (ll j = 1; j <= loop; j++) {
        loop -= j;
        count++;
      }
    }
    if (n != 1) {
      ans = count + 1;
    } else {
      ans = count;
    }
  }
  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// https://atcoder.jp/contests/abc169/tasks/abc169_c
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll ans = 0;
  ll n;
  cin >> n;
  if (n != 1) {
    ll nn = n;
    ll cnt = 0;
    for (int i = 2; i * i <= nn; i++) {
      ll temp = 0;
      while (n % i == 0) {
        n /= i;
        temp++;
      }
      for (int i = 1; i <= temp; i++) {
        temp -= i;
        cnt++;
      }
    }
    if (n != 1) {
      ans = cnt + 1;
    } else {
      ans = cnt;
    }
  }
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;

  int ans = 0;
  long long rt = sqrt(n) + 1;
  vector<bool> is_prime(rt + 1, 1);
  for (long long p = 2; p <= n; p++) {
    if (!is_prime[p])
      continue;
    for (long long k = 2 * p; k <= rt; k += p)
      is_prime[k] = false;
    long long q = p;
    while (n % q == 0) {
      ++ans;
      n /= q;
      q *= p;
    }
    while (n % p == 0)
      n /= p;
    if (p > rt) {
      ++ans;
      break;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;

  int ans = 0;
  long long rt = sqrt(n) + 1;
  vector<bool> is_prime(n + 1, 1);
  for (long long p = 2; p <= n; p++) {
    if (!is_prime[p])
      continue;
    for (long long k = 2 * p; k <= rt; k += p)
      is_prime[k] = false;
    long long q = p;
    while (n % q == 0) {
      ++ans;
      n /= q;
      q *= p;
    }
    while (n % p == 0)
      n /= p;
    if (p > rt) {
      ++ans;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 2; i <= sqrt(n); i++) {
    int tem = i;
    while (n % i == 0) {
      if (n % tem == 0) {
        n /= tem;
        tem *= i;
        sum++;
      } else
        n /= i;
    }
  }
  if (n - 1)
    sum++;
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    int tem = i;
    while (n % i == 0) {
      if (n % tem == 0) {
        n /= tem;
        tem *= i;
        sum++;
      } else
        n /= i;
    }
  }
  cout << sum;
  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<int, int>;

int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll i = 2; i * i <= n; i++) {
    ll x = i;
    while (n % x == 0) {
      n /= x;
      x *= i;
      ans++;
    }
    while (n % i == 0) {
      n /= i;
    }
  }
  if (n != 1)
    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>;

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

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

int main() {
  long long n;
  cin >> n;
  vector<pair<long long, int>> v;
  long long s = sqrt(n);
  for (int i = 2; i <= s; i++) {
    int r = 0;
    while (n % i == 0) {
      r++;
      n /= i;
    }
    if (r != 0)
      v.push_back({i, r});
  }
  if (n != 1)
    v.push_back({n, 1});
  long long ans = 0;
  for (auto e : v) {
    long long x = e.second;
    for (int i = 1; x >= i; i++) {
      x -= i;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  vector<pair<long long, int>> v;
  for (int i = 2; i * i <= n; i++) {
    int r = 0;
    while (n % i == 0) {
      r++;
      n /= i;
    }
    if (r != 0)
      v.push_back({i, r});
  }
  if (n != 1)
    v.push_back({n, 1});
  long long ans = 0;
  for (auto e : v) {
    long long x = e.second;
    for (int i = 1; x >= i; i++) {
      x -= i;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 0;

  for (long long i = 2; i * i <= n; ++i) {
    long long e = 0, z = 0;
    while (n % i == 0) {
      ++e;
      if (e > z) {
        ++ans;
        z = e;
        e = 0;
      }
      n /= i;
    }
  }

  if (n != 1)
    ++ans;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 0;

  for (int i = 2; i * i <= n; ++i) {
    int e = 0, z = 0;
    while (n % i == 0) {
      ++e;
      if (e > z) {
        ++ans;
        z = e;
        e = 0;
      }
      n /= i;
    }
  }

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

#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PIL pair<int, LL>
#define PLI pair<LL, int>
#define PIII pair<int, PII>
#define PLL pair<LL, LL>
#define PLII pair<LL, PII>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i, b, n) for (int i = b; i < n; ++i)
#define rev_loop(i, b, n) for (int i = b; i >= n; --i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e18;
const LL INF = 1e9;

int main() {
  // ofstream out("output.txt");
  // ifstream in("input.txt");
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  /*
  int t,n;
  cin>>t;
  loop(t1,1,t+1)
  {
      int a[n];
      loop(i,0,n) cin>>a[i];
  }
  */

  LL n;
  cin >> n;
  LL ans = 0, n1 = n, c;
  for (LL i = 2; i * i <= n; ++i) {
    if (n1 % i == 0) {
      c = 0;
      while (n1 % i == 0) {
        ++c;
        n1 /= i;
      }
      int j = 1;
      while (c) {
        if (j > c)
          break;
        c -= j;
        ++j;
        ++ans;
      }
    }
  }

  if (n1 != 1)
    ++ans;
  cout << ans << '\\n';

  /*
  if(f) cout<<"Yes"<<'\\n';
  else cout<<"No"<<'\\n';
  */

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PIL pair<int, LL>
#define PLI pair<LL, int>
#define PIII pair<int, PII>
#define PLL pair<LL, LL>
#define PLII pair<LL, PII>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i, b, n) for (int i = b; i < n; ++i)
#define rev_loop(i, b, n) for (int i = b; i >= n; --i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e18;
const LL INF = 1e9;

int main() {
  // ofstream out("output.txt");
  // ifstream in("input.txt");
  // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  /*
  int t,n;
  cin>>t;
  loop(t1,1,t+1)
  {
      int a[n];
      loop(i,0,n) cin>>a[i];
  }
  */

  LL n;
  cin >> n;
  LL ans = 0, n1 = n, c;
  for (int i = 2; i * i <= n; ++i) {
    if (n1 % i == 0) {
      c = 0;
      while (n1 % i == 0) {
        ++c;
        n1 /= i;
      }
      int j = 1;
      while (c) {
        if (j > c)
          break;
        c -= j;
        ++j;
        ++ans;
      }
    }
  }

  if (n1 != 1)
    ++ans;
  cout << ans << '\\n';

  /*
  if(f) cout<<"Yes"<<'\\n';
  else cout<<"No"<<'\\n';
  */

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int main() {

  long long n;
  cin >> n;
  vector<pair<int, int>> v;
  if (n % 2 == 0) {
    int c = 0;
    while (n % 2 == 0) {
      n /= 2;
      c++;
    }
    v.push_back(make_pair(2, c));
  }
  for (long long i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      int c = 0;
      while (n % i == 0) {
        n /= i;
        c++;
      }
      v.push_back(make_pair(i, c));
    }
  }

  int ans = 0;
  for (auto _v : v) {
    for (int i = 1; i * (i - 1) / 2 <= _v.second; i++) {
      ans++;
    }
    ans--;
  }

  if (n != 1)
    ans += 1;

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int main() {

  long long n;
  cin >> n;
  vector<pair<int, int>> v;
  if (n % 2 == 0) {
    int c = 0;
    while (n % 2 == 0) {
      n /= 2;
      c++;
    }
    v.push_back(make_pair(2, c));
  }
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      int c = 0;
      while (n % i == 0) {
        n /= i;
        c++;
      }
      v.push_back(make_pair(i, c));
    }
  }

  int ans = 0;
  for (auto _v : v) {
    for (int i = 1; i * (i - 1) / 2 <= _v.second; i++) {
      ans++;
    }
    ans--;
  }

  if (n != 1)
    ans += 1;

  cout << ans << endl;

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

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

long long f(long long &x, long long &y) {
  while (true) {
    if (x < y * (y + 1) / 2)
      return y - 1;
    y++;
  }
}

int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  vector<long long> a;
  {
    long long cnt = 0;
    while (n % 2 == 0) {
      cnt++;
      n /= 2;
    }
    a.push_back(cnt);
  }
  long long m = n;
  for (long long i = 3; i * i <= m; i += 2) {
    long long cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt > 0)
      a.push_back(cnt);
  }
  if (n != 1)
    a.push_back(1);
  sort(a.begin(), a.end());
  long long mem = 1;
  for (int i = 0; i < a.size(); i++) {
    ans += f(a[i], mem);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

long long f(long long &x, long long &y) {
  while (true) {
    if (x < y * (y + 1) / 2)
      return y - 1;
    y++;
  }
}

int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  vector<long long> a;
  {
    long long cnt = 0;
    while (n % 2 == 0) {
      cnt++;
      n /= 2;
    }
    a.push_back(cnt);
  }
  long long i = 3;
  while (n > 1) {
    long long cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt > 0)
      a.push_back(cnt);
    i += 2;
  }
  sort(a.begin(), a.end());
  long long mem = 1;
  for (int i = 0; i < a.size(); i++) {
    ans += f(a[i], mem);
  }
  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 z;
  int a = 0;
  for (long long i = 2; i * i <= n; ++i) {
    int c = 0;
    while (n % i == 0) {
      n /= i;
      c++;
    }
    for (int j = 1; c > 0; ++j, c -= j) {
      a++;
    }
  }
  if (n != 1)
    a++;
  cout << a;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  int z;
  int a = 0;
  for (int i = 2; i * i <= n; ++i) {
    int c = 0;
    while (n % i == 0) {
      n /= i;
      c++;
    }
    for (int j = 1; c > 0; ++j, c -= j) {
      a++;
    }
  }
  if (n != 1)
    a++;
  cout << a;
}