prithivMLmods/Coder-Stat huggingface dataset:
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a, x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
#define stp(x) setprecision(x)
vlong so;
int findFactors(ll num) {
  int i;
  bool fg = true;
  for (i = 2; i * i <= num; i++) { // 他の素数で割っていく
    while (num % i == 0) {
      fg = false;
      so.push_back(i);
      num /= i;
    }
  }
  if (num != 1) {
    so.push_back(num);
  }
  return 0;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << '\n';
    return (0);
  }
  findFactors(n);
  int now = 2, count = 1, ans = 0, fg = 1;
  ll test = 1;
  rep(i, (int)so.size()) {
    if (now == so[i]) {
      count--;
      if (count == 0) {
        ans++;
        fg++;
        count = fg;
      }
    } else {
      now = so[i];
      ans++;
      fg = 2;
      count = 2;
    }
  }
  cout << ans << '\n';
  return (0);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a, x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
#define stp(x) setprecision(x)
vlong so;
int findFactors(ll num) {
  ll i;
  bool fg = true;
  for (i = 2; i * i <= num; i++) { // 他の素数で割っていく
    while (num % i == 0) {
      fg = false;
      so.push_back(i);
      num /= i;
    }
  }
  if (num != 1) {
    so.push_back(num);
  }
  return 0;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << '\n';
    return (0);
  }
  findFactors(n);
  int now = 2, count = 1, ans = 0, fg = 1;
  ll test = 1;
  rep(i, (int)so.size()) {
    if (now == so[i]) {
      count--;
      if (count == 0) {
        ans++;
        fg++;
        count = fg;
      }
    } else {
      now = so[i];
      ans++;
      fg = 2;
      count = 2;
    }
  }
  cout << ans << '\n';
  return (0);
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n)-1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
  ll n;
  cin >> n;
  vector<ll> p(1000010, 0);
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      p[i]++;
      n /= i;
    }
  }

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

  for (auto &&i : p) {
    ll pnum = i;
    ll cnt = 1;
    while (pnum - cnt >= 0) {
      ans++;
      pnum -= cnt;
      cnt++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n)-1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
  ll n;
  cin >> n;
  vector<int> p(1000010, 0);
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      p[i]++;
      n /= i;
    }
  }

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

  for (auto &&i : p) {
    ll pnum = i;
    ll cnt = 1;
    while (pnum - cnt >= 0) {
      ans++;
      pnum -= cnt;
      cnt++;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: 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 (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;
}


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 (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;
}
Problem p02660 (C++)

Buggy submission (status: 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(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;
}

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(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;
}
Problem p02660 (Python)

Buggy submission (status: Time Limit Exceeded):
from itertools import accumulate
from collections import defaultdict


def main():
    n = int(input())
    prime_counter = defaultdict(int)  # key ^ value
    acc = tuple(accumulate(range(1, 42)))  # because 10^12 < 2^39

    def facs(n):
        yield 2
        for x in range(3, int(n**0.5) + 1, 2):
            yield x
        yield n

    for fac in facs(n):
        while n % fac == 0:
            n //= fac
            prime_counter[fac] += 1
            # ここで if fac * fac > n: braek を入れると，
            # 計算量の少ないケースでは早く，多いケースでは遅くなる。
    if n != 1:
        prime_counter[n] += 1

    ans = 0
    for c in prime_counter.values():
        for i, x in enumerate(acc):
            if c < x:
                tmp = i
                break
        ans += tmp
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from itertools import accumulate
from collections import defaultdict


def main():
    n = int(input())
    prime_counter = defaultdict(int)  # key ^ value
    acc = tuple(accumulate(range(1, 42)))  # because 10^12 < 2^39

    def facs(n):
        yield 2
        for x in range(3, int(n**0.5) + 1, 2):
            yield x

    for fac in facs(n):
        while n % fac == 0:
            n //= fac
            prime_counter[fac] += 1
            # ここで if fac * fac > n: braek を入れると，
            # 計算量の少ないケースでは早く，多いケースでは遅くなる。
    if n != 1:
        prime_counter[n] += 1

    ans = 0
    for c in prime_counter.values():
        for i, x in enumerate(acc):
            if c < x:
                tmp = i
                break
        ans += tmp
    print(ans)


if __name__ == "__main__":
    main()
Problem p02660 (Python)

Buggy submission (status: Runtime Error):
import math


# 素数の判定
def is_prime(n):
    if n == 1:
        return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        chk = False
        while n % k == 0:
            chk = True
            n /= k
            if k not in check:
                check[k] = 1
            else:
                check[k] += 1
        if chk:
            return n
    if n in check:
        return 0
    else:
        check[n] = 1
        return 1


check = {}
n = int(input())
if n == 1:
    print(0)
else:
    while 1:
        n = is_prime(n)
        if n == 0:
            break
    ans = 0
    for k, v in check.items():
        for i in range(1, 50):
            v -= i
            if v < 0:
                break
            else:
                ans += 1
# print(check)
print(ans)


Fixed submission:
import math


# 素数の判定
def is_prime(n):
    if n == 1:
        return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        chk = False
        while n % k == 0:
            chk = True
            n /= k
            if k not in check:
                check[k] = 1
            else:
                check[k] += 1
        if chk:
            return n
    if n in check:
        return 0
    else:
        check[n] = 1
        return 1


check = {}
n = int(input())
if n == 1:
    print(0)
else:
    while 1:
        n = is_prime(n)
        if n == 0:
            break
    ans = 0
    for k, v in check.items():
        for i in range(1, 50):
            v -= i
            if v < 0:
                break
            else:
                ans += 1
    # print(check)
    print(ans)
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  ll N;
  cin >> N;

  ll ans = 0;
  ll NN = N;

  for (int p = 2;; p++) {
    ll cnt = 1;
    while (N % p == 0) {
      // cout << p << endl;
      bool f = false;
      for (int i = 0; i < cnt; i++) {
        if (N % p == 0) {
          N /= p;
        } else {
          f = true;
          break;
        }
      }
      if (f)
        break;
      cnt++;
      ans++;
    }
    if (p * p > N)
      break;
  }

  if (N != 1)
    ans++;
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  ll N;
  cin >> N;

  ll ans = 0;
  ll NN = N;

  for (ll p = 2;; p++) {
    ll cnt = 1;
    while (N % p == 0) {
      // cout << p << endl;
      bool f = false;
      for (int i = 0; i < cnt; i++) {
        if (N % p == 0) {
          N /= p;
        } else {
          f = true;
          break;
        }
      }
      if (f)
        break;
      cnt++;
      ans++;
    }
    if (p * p > N)
      break;
  }

  if (N != 1)
    ans++;
  cout << ans << endl;

  return 0;
}
Problem p02660 (C++)

Buggy submission (status: 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;
  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;
}


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;
  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;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
// g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include <ostream>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

bool sosuhantei(ll x) {
  if (x == 1)
    return false;
  if (x == 2)
    return true;
  if (x == 3)
    return true;
  int i = 2;
  bool res = true;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      res = false;
      break;
    }
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll M = N;
  ll max = 1;
  for (ll i = 1; i * i <= N; i++)
    max = i;
  vector<ll> num;
  map<ll, ll> cnt;
  for (int i = 2; i <= max; i++) {
    if (M % i == 0)
      num.push_back(i);
    while (M % i == 0) {
      cnt[i]++;
      M /= i;
    }
    if (sosuhantei(M)) {
      num.push_back(M);
      cnt[M]++;
      break;
    }
  } /*
   rep(i,num.size()){
     cout << num[i] << " ";
   }
   cout << endl;
   */
  ll ans = 0;
  for (int i = 0; i < num.size(); i++) {
    int j = 1;
    while (cnt[num[i]] - j >= 0) {
      cnt[num[i]] -= j;
      j++;
      ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
// g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include <ostream>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

bool sosuhantei(ll x) {
  if (x == 1)
    return false;
  if (x == 2)
    return true;
  if (x == 3)
    return true;
  int i = 2;
  bool res = true;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      res = false;
      break;
    }
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll M = N;
  ll max = 1;
  for (ll i = 1; i * i <= N; i++)
    max = i;
  vector<ll> num;
  map<ll, ll> cnt;
  for (int i = 2; i <= max; i++) {
    if (M % i == 0)
      num.push_back(i);
    while (M % i == 0) {
      cnt[i]++;
      M /= i;
    }
  }
  if (M != 1) {
    num.push_back(M);
    cnt[M]++;
  }
  /*
  rep(i,num.size()){
    cout << num[i] << " ";
  }
  cout << endl;
  */
  ll ans = 0;
  for (int i = 0; i < num.size(); i++) {
    int j = 1;
    while (cnt[num[i]] - j >= 0) {
      cnt[num[i]] -= j;
      j++;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: 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 (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;
}


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 (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;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long n, cnt = 0;
  cin >> n;
  map<long, int> v;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      v[i]++;
      n /= i;
    }
  }
  if (n != 1)
    v[n] = 1;
  for (auto i : v) {
    int k = 1, d = i.second;
    while (0 <= d - k) {
      d -= k;
      k++;
    }
    cnt += k - 1;
  }
  cout << cnt << endl;
}

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

int main() {
  long n, cnt = 0;
  cin >> n;
  map<long, int> v;
  for (long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      v[i]++;
      n /= i;
    }
  }
  if (n != 1)
    v[n] = 1;
  for (auto i : v) {
    int k = 1, d = i.second;
    while (0 <= d - k) {
      d -= k;
      k++;
    }
    cnt += k - 1;
  }
  cout << cnt << endl;
}
Problem p02660 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

long long freq[1000005];
vector<long long> sums;

int main() {
  long long N;
  scanf("%lld", &N);

  if (N == 1) {
    printf("0");
    return 0;
  }

  long long tempN = N, i = 2;
  while (i * i <= tempN) {
    if (N % i == 0) {
      N /= i;
      freq[i]++;
    }

    else
      i++;
  }

  long long ans = 0;
  if (N == tempN) {
    printf("1");
    return 0;
  }

  else if (N > 1) {
    freq[N]++;
    ans++;
  }

  i = 0;
  while (true) {
    sums.push_back(i * (i + 1) / 2);
    if (sums.back() >= (long long)(1E6) * (long long)(1E6))
      break;

    i++;
  }

  for (long long int i = 0; i < 1000005; i++) {
    if (freq[i] == 0)
      continue;

    long long pos =
        upper_bound(sums.begin(), sums.end(), freq[i]) - sums.begin();
    ans += pos - 1;
  }

  printf("%lld", ans);
}


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

long long freq[1000005];
vector<long long> sums;

int main() {
  long long N;
  scanf("%lld", &N);

  if (N == 1) {
    printf("0");
    return 0;
  }

  long long tempN = N, i = 2;
  while (i * i <= tempN) {
    if (N % i == 0) {
      N /= i;
      freq[i]++;
    }

    else
      i++;
  }

  long long ans = 0;
  if (N == tempN) {
    printf("1");
    return 0;
  }

  else if (N > 1) {
    // freq[N]++;
    ans++;
  }

  i = 0;
  while (true) {
    sums.push_back(i * (i + 1) / 2);
    if (sums.back() >= (long long)(1E6) * (long long)(1E6))
      break;

    i++;
  }

  for (long long int i = 0; i < 1000005; i++) {
    if (freq[i] == 0)
      continue;

    long long pos =
        upper_bound(sums.begin(), sums.end(), freq[i]) - sums.begin();
    ans += pos - 1;
  }

  printf("%lld", ans);
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

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

  int count = 0;
  for (auto p : A) {
    int b = 1;
    int y = p.second;
    while (y >= b) {
      y -= b;
      b++;
      count++;
    }
  }
  cout << count << endl;
}


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

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

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

  int count = 0;
  for (auto p : A) {
    int b = 1;
    int y = p.second;
    while (y >= b) {
      y -= b;
      b++;
      count++;
    }
  }
  cout << count << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02660 (C++)

Buggy submission (status: 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 (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;
}

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 (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;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ll n;
  int ans = 0;
  cin >> n;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      int tmp = 1;
      while (cnt >= tmp) {
        ++ans;
        cnt -= tmp;
        ++tmp;
      }
    }
  }
  if (n != 1)
    ++ans;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ll n;
  int ans = 0;
  cin >> n;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      int tmp = 1;
      while (cnt >= tmp) {
        ++ans;
        cnt -= tmp;
        ++tmp;
      }
    }
  }
  if (n != 1)
    ++ans;
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t a;
  int64_t c = 0;
  int64_t z = 0;
  int64_t h = 0;
  vector<int64_t> vec;
  vector<int64_t> ans;
  cin >> a;
  if (a == 1) {
    h = 0;
  }

  if (a != 1) {
    while (a >= 2) {
      if (a == 2) {
        vec.push_back(2);
        break;
      }
      if (a >= 3) {
        for (int64_t i = 2; i <= sqrt(a); i++) {
          c = 0;
          if (a % i == 0) {
            vec.push_back(i);
            a = a / i;
            c = 1;
            break;
          }
        }
      }
      if (c == 0) {
        vec.push_back(a);
        break;
      }
    }
    sort(vec.begin(), vec.end());
    vec.push_back(4);
    int64_t t = vec.size();

    for (int64_t i = 0; i < t - 1; i++) {
      if (vec.at(i) == vec.at(i + 1)) {
        z++;
      } else {
        ans.push_back(z + 1);
        z = 0;
      }
    }
    int64_t s = ans.size();
    for (int64_t i = 0; i < s; i++) {
      for (int64_t j = 0; j < 100; j++) {
        if (j * (j + 1) / 2 <= ans.at(i) && ans.at(i) < (j + 1) * (j + 2) / 2) {
          h = h + j;
          break;
        }
      }
    }
  }

  cout << h << endl;
}

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

int main() {
  int64_t a;
  int64_t c = 0;
  int64_t z = 0;
  int64_t h = 0;
  vector<int64_t> vec;
  vector<int64_t> ans;
  cin >> a;
  if (a == 1) {
    h = 0;
  }

  if (a != 1) {
    while (a >= 2) {
      if (a == 2) {
        vec.push_back(2);
        break;
      }
      if (a >= 3) {
        c = 0;
        for (int64_t i = 2; i <= sqrt(a); i++) {
          c = 0;
          if (a % i == 0) {
            vec.push_back(i);
            a = a / i;
            c = 1;
            break;
          }
        }
      }
      if (c == 0) {
        vec.push_back(a);
        break;
      }
    }
    sort(vec.begin(), vec.end());
    vec.push_back(4);
    int64_t t = vec.size();

    for (int64_t i = 0; i < t - 1; i++) {
      if (vec.at(i) == vec.at(i + 1)) {
        z++;
      } else {
        ans.push_back(z + 1);
        z = 0;
      }
    }
    int64_t s = ans.size();
    for (int64_t i = 0; i < s; i++) {
      for (int64_t j = 0; j < 100; j++) {
        if (j * (j + 1) / 2 <= ans.at(i) && ans.at(i) < (j + 1) * (j + 2) / 2) {
          h = h + j;
          break;
        }
      }
    }
  }

  cout << h << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PP = pair<int, pair<int, int>>;
using T = tuple<string, int, int>;
const string EMP = " ";
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int c = 0;
      while (n % i == 0) {
        c++;
        n /= i;
      }
      for (int j = 1; j <= c; j++) {
        ans++;
        c -= j;
      }
    }
  }
  if (n != 1)
    ans++;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PP = pair<int, pair<int, int>>;
using T = tuple<string, int, int>;
const string EMP = " ";
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int c = 0;
      while (n % i == 0) {
        c++;
        n /= i;
      }
      for (int j = 1; j <= c; j++) {
        ans++;
        c -= j;
      }
    }
  }
  if (n != 1)
    ans++;
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PP = pair<int, pair<int, int>>;
using T = tuple<string, int, int>;
const ll INF = 1LL << 60;

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using PP = pair<int, pair<int, int>>;
using T = tuple<string, int, int>;
const ll INF = 1LL << 60;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      for (int j = 1; j <= cnt; j++) {
        ans++;
        cnt -= j;
      }
    }
  }
  if (n != 1)
    ans++;
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: 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;

map<ll, ll> factorization(ll n) {
  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 = factorization(n);
  ll ans = 0;
  for (auto x : mp) {
    ll i = 1;
    while (x.second >= i) {
      ans++;
      x.second -= i;
      i++;
    }
  }

  cout << ans << endl;
}

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

map<ll, ll> factorization(ll n) {
  map<ll, ll> res;
  for (ll 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 = factorization(n);
  ll ans = 0;
  for (auto x : mp) {
    ll i = 1;
    while (x.second >= i) {
      ans++;
      x.second -= i;
      i++;
    }
  }

  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

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


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

typedef long long ll;

int main() {
  ll N;
  ll ans = 0;
  cin >> N;
  for (ll i = 2; i * i <= N; i++) {
    if (N % i != 0)
      continue;
    ll z = i;
    while (N % z == 0) {
      N /= z;
      z *= i;
      ans++;
    }
    while (N % i == 0) {
      N /= i;
    }
  }
  if (N != 1)
    ans++;
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  unordered_map<int, int> factor;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      factor[i] += 1;
      n /= i;
    }
  }
  if (n != 1)
    factor[n] += 1;
  int ans = 0;
  for (auto x : factor) {
    for (int i = 1; i <= x.second; i++) {
      x.second -= i;
      ans += 1;
    }
  }
  cout << ans << endl;
}


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

int main() {
  ll n;
  cin >> n;
  map<int, int> factor;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      factor[i] += 1;
      n /= i;
    }
  }
  if (n != 1)
    factor[n] += 1;
  int ans = 0;
  for (auto x : factor) {
    for (int i = 1; i <= x.second; i++) {
      x.second -= i;
      ans += 1;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <iostream>
#include <numeric>
#include <vector>

int main() {
  int64_t N;
  std::cin >> N;

  size_t i = 2;
  int64_t R = 0;
  while (i <= N) {
    int64_t c = 0;
    while (N % i == 0) {
      N /= i;
      ++c;
    }
    if (c != 0) {
      size_t t = 1;
      size_t j = 1;
      while (t <= c) {
        ++j;
        t += j;
      }
      R += j - 1;
    }
    ++i;
  }
  std::cout << R << std::endl;

  return 0;
}

Fixed submission:

#include <iostream>
#include <numeric>
#include <vector>

int main() {
  int64_t N;
  std::cin >> N;

  size_t i = 2;
  int64_t R = 0;
  while (i <= N) {
    int64_t c = 0;
    while (N % i == 0) {
      N /= i;
      ++c;
    }
    if (c != 0) {
      size_t t = 1;
      size_t j = 1;
      while (t <= c) {
        ++j;
        t += j;
      }
      R += j - 1;
    } else {
      if (i * i > N) {
        ++R;
        break;
      }
    }
    ++i;
  }
  std::cout << R << std::endl;

  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main() {
  ll n;
  ll result = 0;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<pair<ll, int>> p;
  for (int i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    p.emplace_back(i, cnt);
  }
  if (n != 1) {
    p.emplace_back(n, 1);
  }

  for (auto x : p) {
    int num = x.second;
    int count = 1;
    while (count <= num) {
      num -= count;
      result++;
      count++;
    }
  }
  cout << result << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main() {
  ll n;
  ll result = 0;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<pair<ll, int>> p;
  for (ll i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    p.emplace_back(i, cnt);
  }
  if (n != 1) {
    p.emplace_back(n, 1);
  }

  for (auto x : p) {
    int num = x.second;
    int count = 1;
    while (count <= num) {
      num -= count;
      result++;
      count++;
    }
  }
  cout << result << endl;
}
Problem p02660 (C++)

Buggy submission (status: 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 (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;
}

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 (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;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
map<int, int> mp;
int tri(int n) {
  int x = 0;
  for (int i = 1;; i++) {
    if (x + i > n) {
      return i - 1;
    } else
      x += i;
  }
  return 0;
}
vector<int> vec;
signed main() {
  int n;
  int ans = 0;
  cin >> n;
  int nn = n;
  for (int i = 2; i <= nn; i++) {
    if (n % i == 0) {
      mp[i]++;
      n /= i;
      i--;
    }
    if (n == 1) {
      break;
    }
  }
  if (n > 1) {
    mp[n]++;
  }
  for (auto x : mp) {
    ans += tri(x.second);
  }
  if (ans == 0 && n > 1)
    cout << 1 << endl;
  else
    cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
map<int, int> mp;
int tri(int n) {
  int x = 0;
  for (int i = 1;; i++) {
    if (x + i > n) {
      return i - 1;
    } else
      x += i;
  }
  return 0;
}
vector<int> vec;
signed main() {
  int n;
  int ans = 0;
  cin >> n;
  int nn = n;
  for (int i = 2; i <= sqrt(nn); i++) {
    if (n % i == 0) {
      mp[i]++;
      n /= i;
      i--;
    }
    if (n == 1) {
      break;
    }
  }
  if (n > 1) {
    mp[n]++;
  }
  for (auto x : mp) {
    ans += tri(x.second);
  }
  if (ans == 0 && n > 1)
    cout << 1 << endl;
  else
    cout << ans << endl;
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

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

  long long n;
  cin >> n;
  map<int, int> mp;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0)
        cnt++, n /= i;
      mp[i] = cnt;
    }
  }
  if (n > 1)
    mp[n] = 1;
  int ans = 0;
  for (auto [f, s] : mp) {
    for (int i = 1; s >= i; ++i) {
      s -= i;
      ans++;
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

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

  long long n;
  cin >> n;
  map<long long, int> mp;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0)
        cnt++, n /= i;
      mp[i] = cnt;
    }
  }
  if (n > 1)
    mp[n] = 1;
  int ans = 0;
  for (auto [f, s] : mp) {
    for (int i = 1; s >= i; ++i) {
      s -= i;
      ans++;
    }
  }
  cout << ans;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n;
  cin >> n;
  int ans = 0;
  int tmp = 0;
  vector<int> a;

  for (int i = 2; i <= n; i++) {
    if (n < i * i) {
      ans++;
      break;
    }
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      a.push_back(cnt);
      tmp++;
    }
  }
  for (int i = 0; i < tmp; i++) {
    int k = 0;
    for (int j = 1; j * (j + 1) / 2 <= a[i]; j++) {
      k = j;
    }
    ans += k;
  }
  cout << ans << endl;
}


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

int main() {
  long long n;
  cin >> n;
  int ans = 0;
  int tmp = 0;
  vector<int> a;

  for (long long i = 2; i <= n; i++) {
    if (n < i * i) {
      ans++;
      break;
    }
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      a.push_back(cnt);
      tmp++;
    }
  }
  for (int i = 0; i < tmp; i++) {
    int k = 0;
    for (int j = 1; j * (j + 1) / 2 <= a[i]; j++) {
      k = j;
    }
    ans += k;
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++)
#define all(x) x.begin(), x.end()

template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) {
  return std::vector<T>(n, std::forward<T>(val));
}
template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(
      n, ndvec(std::forward<Tail>(tail)...));
}
template <class Cond> struct chain {
  Cond cond;
  chain(Cond cond) : cond(cond) {}
  template <class T> bool operator()(T &a, const T &b) const {
    if (cond(a, b)) {
      a = b;
      return true;
    }
    return false;
  }
};
template <class Cond> chain<Cond> make_chain(Cond cond) {
  return chain<Cond>(cond);
}

int main() {
  i64 N;
  cin >> N;
  map<i64, i64> mp;
  for (int i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      i64 cnt = 0;
      while (N % i == 0) {
        cnt++;
        N /= i;
      }
      mp[i] = cnt;
    }
  }
  if (N > 1) {
    mp[N] = 1;
  }
  i64 ans = 0;
  for (auto pp : mp) {
    auto p = pp.second;
    i64 ok = 0;
    i64 ng = 1e9;
    for (int i = 0; i < 50; i++) {
      i64 mid = (ok + ng) / 2;
      if (mid * (mid + 1) / 2 <= p) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    ans += ok;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++)
#define all(x) x.begin(), x.end()

template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) {
  return std::vector<T>(n, std::forward<T>(val));
}
template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(
      n, ndvec(std::forward<Tail>(tail)...));
}
template <class Cond> struct chain {
  Cond cond;
  chain(Cond cond) : cond(cond) {}
  template <class T> bool operator()(T &a, const T &b) const {
    if (cond(a, b)) {
      a = b;
      return true;
    }
    return false;
  }
};
template <class Cond> chain<Cond> make_chain(Cond cond) {
  return chain<Cond>(cond);
}

int main() {
  i64 N;
  cin >> N;
  map<i64, i64> mp;
  for (i64 i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      i64 cnt = 0;
      while (N % i == 0) {
        cnt++;
        N /= i;
      }
      mp[i] = cnt;
    }
  }
  if (N > 1) {
    mp[N] = 1;
  }
  i64 ans = 0;
  for (auto pp : mp) {
    auto p = pp.second;
    i64 ok = 0;
    i64 ng = 1e9;
    for (int i = 0; i < 50; i++) {
      i64 mid = (ok + ng) / 2;
      if (mid * (mid + 1) / 2 <= p) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    ans += ok;
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define inp(arr, n)                                                            \
  for (int i = 0; i < n; i++)                                                  \
  cin >> arr[i]
#define fr(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> p;
  vector<ll> f;
  if (n % 2 == 0) {
    ll count = 0;
    while (n % 2 == 0) {
      count++;
      n /= 2;
    }
    p.push_back(2);
    f.push_back(count);
  }
  for (ll i = 3; i <= (ll)sqrt(n); i += 2) {
    if (n % i == 0) {
      ll count = 0;
      while (n % i == 0) {
        count++;
        n /= i;
      }
      p.push_back(i);
      f.push_back(count);
    }
  }
  if (n > 2) {
    p.push_back(n);
    f.push_back(1);
  }
  ll c = 0;
  fr(i, 0, f.size() - 1) {
    ll a = f[i];
    ll b = (ll)((-1 + sqrt(1 + 8 * a)) / 2);
    c += b;
  }
  cout << c << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define inp(arr, n)                                                            \
  for (int i = 0; i < n; i++)                                                  \
  cin >> arr[i]
#define fr(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> p;
  vector<ll> f;
  if (n % 2 == 0) {
    ll count = 0;
    while (n % 2 == 0) {
      count++;
      n /= 2;
    }
    p.push_back(2);
    f.push_back(count);
  }
  for (ll i = 3; i <= (ll)sqrt(n); i += 2) {
    if (n % i == 0) {
      ll count = 0;
      while (n % i == 0) {
        count++;
        n /= i;
      }
      p.push_back(i);
      f.push_back(count);
    }
  }
  if (n > 2) {
    p.push_back(n);
    f.push_back(1);
  }
  ll c = 0;
  fr(i, 0, f.size() - 1) {
    ll a = f[i];
    ll b = (ll)((-1 + sqrt(1 + 8 * a)) / 2);
    c += b;
  }
  cout << c << endl;
  return 0;
}