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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set =
    tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

/*
if you have any question about any part of my code,
please don't shy to ask anytime :)
*/

bool isprime(ll n) {
  if (n == 2)
    return true;

  if (n % 2 == 0 || n < 2)
    return false;

  for (int i = 3; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }

  return true;
}

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;

  unordered_set<ll> s;
  unordered_map<ll, ll> h;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      s.insert(i);
      n /= i;
      h[i]++;
    }
  }

  if (n > 1) {
    s.insert(n);
    h[n]++;
  }

  for (auto it : s) {
    for (int i = 1;; i++) {
      if (h[it] >= i) {
        ans++;
        h[it] -= i;
      } else {
        break;
      }
    }
  }

  cout << ans << endl;
}

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

  // ll t;
  // cin >> t;

  // while (t--)
  // {
  //     solve();
  // }
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set =
    tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

/*
if you have any question about any part of my code,
please don't shy to ask anytime :)
*/

bool isprime(ll n) {
  if (n == 2)
    return true;

  if (n % 2 == 0 || n < 2)
    return false;

  for (int i = 3; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }

  return true;
}

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;

  unordered_set<ll> s;
  unordered_map<ll, ll> h;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      s.insert(i);
      n /= i;
      h[i]++;
    }
  }

  if (n > 1) {
    s.insert(n);
    h[n]++;
  }

  for (auto it : s) {
    for (int i = 1;; i++) {
      if (h[it] >= i) {
        ans++;
        h[it] -= i;
      } else {
        break;
      }
    }
  }

  cout << ans << endl;
}

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

  // ll t;
  // cin >> t;

  // while (t--)
  // {
  //     solve();
  // }
  solve();
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

bool isPrime(ll num) {
  if (num < 2)
    return false;

  for (ll i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    int num = 0;
    while (n % i == 0) {
      num++;
      n /= i;
    }
    res.push_back(make_pair(i, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));

  return res;
}

int main() {
  ll n;
  cin >> n;
  auto x = prime_factorize(n);
  ll ans = 0;

  // for (int i = 0; i <= 14; i++) {
  //     cout << x[i].first << " " << x[i].second << endl;
  // }

  for (auto i : x) {
    ll current = i.first;
    while (n % current == 0) {
      ans++;
      n /= current;
      current *= i.first;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

bool isPrime(ll num) {
  if (num < 2)
    return false;

  for (ll i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  vector<int> x(n + 1, 0);
  ll tmp;
  ll ans = 0;
  ll num1 = n;
  for (ll i = 2; i * i <= num1; i++) {
    if (isPrime(i)) {
      tmp = i;
      while (n % tmp == 0) {
        ans++;
        n /= tmp;
        // cout << i << " " << tmp << " " << n << endl;
        tmp *= i;
      }
    }
  }
  if (n % num1 == 0)
    ans++;
  cout << ans << endl;

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back(make_pair(a, ex));
  }

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

int main() {
  ll N;
  cin >> N;
  const auto &res = prime_factorize(N);
  // cout << N << ":";
  /*for (auto p : res) {
      for (int i = 0; i < p.second; ++i) cout << " " << p.first;
  }*/
  int ans = 0;
  for (auto p : res) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;

int div(int n) {
  int j = 0;
  rep(i, 2, n + 1) {
    if (n % i == 0) {
      n /= i;
      j++;
    }
  }
  return j;
}

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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
const int mod = 1e9 + 7;

map<ll, ll> prime_factor(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] = 1;
  return res;
}

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp = prime_factor(n);

  ll res = 0;
  for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
    ll num = iter->second;
    ll tmp = 0;
    while (1) {
      if (tmp * (tmp + 1) <= 2 * num && 2 * num < (tmp + 1) * (tmp + 2)) {
        res += tmp;
        break;
      }
      tmp++;
    }
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
const int mod = 1e9 + 7;

map<ll, ll> prime_factor(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] = 1;
  return res;
}

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp = prime_factor(n);

  ll res = 0;
  for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
    ll num = iter->second;
    ll tmp = ((ll)sqrt(1 + 8 * num) - 1) / 2;
    while (1) {
      if (tmp * (tmp + 1) <= 2 * num && 2 * num < (tmp + 1) * (tmp + 2)) {
        res += tmp;
        break;
      }
      tmp++;
    }
  }
  cout << res << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll k = n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; ++i) {
    int count = 0;
    while (k % i == 0) {
      k /= i;
      count++;
    }
    for (int j = 1; j <= count; ++j) {
      count -= j;
      ans++;
    }
  }
  if (1 < k) {
    ans++;
  }

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


Error: TLE

Fixed submission:

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;

  ll copy_n = n;

  vector<P> res;
  for (ll i = 2; i <= n; ++i) {
    if (n % i == 0) {
      int count = 0;
      while (n % i == 0) {
        n /= i;
        count++;
      }
      res.push_back(P(i, count));
    }
  }

  // for(auto tt : res){
  //   cout << tt.first << " " << tt.second << endl;
  // }

  ll ans = 0;
  if (res.size() == 0) {
    if (copy_n == 1) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  } else {
    for (auto tmp : res) {
      ll div = tmp.first;
      for (ll i = 0; i < tmp.second; ++i) {
        if (copy_n % div == 0) {
          // cout << div << " " << copy_n << endl;
          copy_n /= div;
          ans++;
        } else {
          break;
        }
        div *= tmp.first;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

#define ll long long
using namespace std;
const int lim = 5e6;
int lp[lim + 10], pr[lim], cnt = 0;
vector<ll> V;
unordered_map<ll, int> mp;
ll n;
void sieve() {
  for (int i = 2; i <= lim; i++) {
    if (lp[i] == 0)
      lp[i] = pr[++cnt] = i;
    int j = 1;
    while (j <= cnt && pr[j] <= lp[i] && i * pr[j] <= lim) {
      lp[i * pr[j]] = pr[j];
      j++;
    }
  }
}
bool prime(long long x) {
  if (x < 2)
    return false;
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}
void add() {
  for (ll i = 2; i <= lim; i++)
    if (lp[i] == i)
      for (ll temp = i; temp <= (ll)1e13; temp *= i)
        V.push_back(temp);
}
int main() {
  /*sieve();
  add();
  sort(V.begin(),V.end());
  cin >> n;
  ll ans = 0 , tmp = 1;
  for (auto x : V)
      if (n % x == 0 && x <= n) n /= x , ans++ , tmp = x;
  if (prime(n) == true && n > tmp) ans++;
  cout << ans;*/
  ll ans = 0;
  cin >> n;
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
        mp[i]++;
      }
      V.push_back(i);
    }
  if (n > 1)
    V.push_back(n), mp[n]++;
  for (auto x : V) {
    int sum = 1;
    while (mp[x] >= sum)
      mp[x] -= sum, ans++, sum++;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

#define ll long long
using namespace std;
const int lim = 5e6;
int lp[lim + 10], pr[lim], cnt = 0;
vector<ll> V;
unordered_map<ll, int> mp;
ll n;
void sieve() {
  for (int i = 2; i <= lim; i++) {
    if (lp[i] == 0)
      lp[i] = pr[++cnt] = i;
    int j = 1;
    while (j <= cnt && pr[j] <= lp[i] && i * pr[j] <= lim) {
      lp[i * pr[j]] = pr[j];
      j++;
    }
  }
}
bool prime(long long x) {
  if (x < 2)
    return false;
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}
void add() {
  for (ll i = 2; i <= lim; i++)
    if (lp[i] == i)
      for (ll temp = i; temp <= (ll)1e13; temp *= i)
        V.push_back(temp);
}
int main() {
  /*sieve();
  add();
  sort(V.begin(),V.end());
  cin >> n;
  ll ans = 0 , tmp = 1;
  for (auto x : V)
      if (n % x == 0 && x <= n) n /= x , ans++ , tmp = x;
  if (prime(n) == true && n > tmp) ans++;
  cout << ans;*/
  ll ans = 0;
  cin >> n;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
        mp[i]++;
      }
      V.push_back(i);
    }
  if (n > 1)
    V.push_back(n), mp[n]++;
  for (auto x : V) {
    int sum = 1;
    while (mp[x] >= sum)
      mp[x] -= sum, ans++, sum++;
  }
  cout << ans;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9 + 100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  ll input = n;
  for (ll i = 2; i * i <= input; i++) {
    if (input % i == 0) {
      while (input % i == 0) {
        input /= i;
        mp[i]++;
      }
    }
  }
  if (input != 1)
    mp[input]++;

  ll ans = 0;
  map<ll, ll>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    ans += (sqrt(1 + 8 * it->second) - 1) / 2;
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9 + 100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  ll input = n;

  for (int i = 2; i * i <= input; i++) {
    if (input % i == 0) {
      while (input % i == 0) {
        input /= i;
        mp[i]++;
      }
    }
  }
  if (input != 1)
    mp[input]++;

  ll ans = 0;

  map<ll, ll>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    ans += (sqrt(1 + 8 * it->second) - 1) / 2;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll prime[1000005], cnt;
bool vis[1000005];
ll ans = 0;
const ll A[64] = {0, 1, 1, 2, 2, 2, 3, 3,  3,  3,  4,  4,  4,  4,  4,  5,
                  5, 5, 5, 5, 5, 6, 6, 6,  6,  6,  6,  6,  7,  7,  7,  7,
                  7, 7, 7, 7, 8, 8, 8, 8,  8,  8,  8,  8,  8,  9,  9,  9,
                  9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10};
inline void solve(int n) {
  for (int i = 2; i <= n; i++) {
    if (!vis[i])
      prime[cnt++] = i;
    for (int j = 0; j < cnt && i * prime[j] <= n; j++) {
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
inline void calc(long long n) {
  for (int i = 0; i < cnt; ++i) {
    if (n % prime[i] == 0) {
      long long x = prime[i];
      long long a = 0;
      while (n % x == 0) {
        a++;
        n /= x;
      }
      ans += A[a];
    }
  }
  if (n != 1) {
    ans++;
  }
}
int main() {
  solve(1e6);
  cin >> n;
  calc(n);
  cout << ans << '\\n';
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll prime[1000005], cnt;
bool vis[1000005];
ll ans = 0;
const ll A[64] = {0, 1, 1, 2, 2, 2, 3, 3,  3,  3,  4,  4,  4,  4,  4,  5,
                  5, 5, 5, 5, 5, 6, 6, 6,  6,  6,  6,  6,  7,  7,  7,  7,
                  7, 7, 7, 7, 8, 8, 8, 8,  8,  8,  8,  8,  8,  9,  9,  9,
                  9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10};
inline void solve(int n) {
  for (int i = 2; i <= n; i++) {
    if (!vis[i])
      prime[cnt++] = i;
    for (int j = 0; j < cnt && i * prime[j] <= n; j++) {
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
inline void calc(int n, int b) {
  if (n == 1) {
    return;
  }
  if (b == cnt) {
    ans++;
    return;
  }
  int a;
  int x;
  int i;
  for (i = b; i < cnt; ++i) {
    if (n % prime[i] == 0) {
      x = prime[i];
      break;
    }
  }
  while (n % x == 0) {
    a++;
    n /= x;
  }
  ans += A[a];
  calc(n, i + 1);
}
int main() {
  solve(1e6);
  cin >> n;
  calc(n, 0);
  cout << ans << '\\n';
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int solve(int m) {
  int lo = 0, hi = 65;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (mid * (mid + 1) / 2 > m)
      hi = mid - 1;
    else
      lo = mid + 1;
  }
  return lo - 1;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  long long n;
  cin >> n;
  int res = 0, exp = 0;
  while (n % 2 == 0) {
    n /= 2;
    ++exp;
  }
  res += solve(exp);
  for (long long i = 3; i * i <= n; i += 2) {
    int exp = 0;
    while (n % i == 0) {
      n /= i;
      ++exp;
    }
    res += solve(exp);
  }
  if (n >= 2)
    ++res;
  cout << res << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  long long n;
  cin >> n;
  int res = 0;
  for (int i = 2; i * i <= n; ++i) {
    int exp = 0;
    while (n % i == 0) {
      n /= i;
      ++exp;
    }
    if (exp > 0) {
      int lo = 0, hi = 1000;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (mid * (mid + 1) / 2 > exp)
          hi = mid - 1;
        else
          lo = mid + 1;
      }
      res += lo - 1;
    }
  }
  if (n >= 2)
    ++res;
  cout << res << '\\n';
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, c, q, d = 0;
  map<long long int, long long int> m;
  cin >> n;
  for (i = 2; i * i < n; i++) {
    c = 0;
    while (n % i == 0) {
      c++;
      n = n / i;
    }
    m[i] = c;
    if (c > 0) {
      q = 2 * m[i];
      d += (-1 + pow((1 + 4 * q), 0.5)) / 2;
    }
  }
  if (n != 1) {
    m[n] = 1;
    d++;
  }
  cout << d;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
  lli n, i, c = 0, q, d;
  map<lli, lli> m;
  cin >> n;
  d = 0;
  if (n == 1) {
    cout << "0";
    return 0;
  }
  for (i = 2; i <= n; i++) {
    c = 0;
    while (n % i == 0) {
      c++;
      n = n / i;
    }
    m[i] = c;
    if (c > 0) {
      q = 2 * m[i];
      d += (-1 + pow((1 + 4 * q), 0.5)) / 2;
    }
  }
  cout << d;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
const ll INF_ = 1000000000000000000;

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

int main() {
  map<int64_t, int> m;
  auto aa = prime_factor(1000000007);
  ll n;
  int cnt = 0;
  cin >> n;
  set<ll> s;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      s.insert(i);
      if (i * i != n)
        s.insert(n / i);
    }
  }
  s.erase(1);
  for (auto itr : s) {
    if (n == 1)
      break;
    if (itr < 0)
      continue;
    m.clear();
    m = prime_factor(itr);
    if (m.size() != 1)
      continue;
    if (n % itr == 0) {
      n /= itr;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
const ll INF_ = 1000000000000000000;

int main() {
  ll n;
  int cnt = 0;
  cin >> n;
  set<int> s;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      s.insert(i);
      if (i * i != n)
        s.insert(n / i);
    }
  }
  s.erase(1);
  for (auto itr : s) {
    if (n == 1)
      break;
    if (itr < 0)
      continue;
    if (n % itr == 0) {
      n /= itr;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long n;
vector<pair<int, int>> ve;

void factorize(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int temp = 0;
      while (n % i == 0) {
        n /= i;
        temp++;
      }
      ve.emplace_back(i, temp);
    }
  }
  if (n > 1) {
    ve.emplace_back(n, 1);
  }
}

int f(int a) {
  int r = a, l = 0, ans = -1;
  while (r >= l) {
    int mid = (r + l) / 2;
    if (mid * (mid + 1) / 2 > a) {
      r = mid - 1;
    } else {
      ans = mid;
      l = mid + 1;
    }
  }
  return ans;
}

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

  cin >> n;
  factorize(n);

  int ans = 0;
  for (auto i : ve) {
    ans += f(i.second);
  }
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

long long n;
vector<pair<int, int>> ve;

void factorize(long long n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int temp = 0;
      while (n % i == 0) {
        n /= i;
        temp++;
      }
      ve.emplace_back(i, temp);
    }
  }
  if (n > 1) {
    ve.emplace_back(n, 1);
  }
}

int f(int a) {
  int r = a, l = 0, ans = -1;
  while (r >= l) {
    int mid = (r + l) / 2;
    if (mid * (mid + 1) / 2 > a) {
      r = mid - 1;
    } else {
      ans = mid;
      l = mid + 1;
    }
  }
  return ans;
}

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

  cin >> n;
  factorize(n);

  int ans = 0;
  for (auto i : ve) {
    ans += f(i.second);
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9 + 100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  FIN;
  ll n;
  cin >> n;
  auto pf = prime_factorize(n);

  ll ans = 0;
  for (auto p : pf) {
    ans += (sqrt(1 + 8 * p.second) - 1) / 2;
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9 + 100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

int main() {
  FIN;
  ll n;
  cin >> n;
  map<ll, ll> mp;
  ll input = n;

  for (int i = 2; i * i <= input; i++) {
    if (input % i == 0) {
      while (input % i == 0) {
        input /= i;
        mp[i]++;
      }
    }
  }
  if (input != 1)
    mp[input]++;

  ll ans = 0;

  map<ll, ll>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    ans += (sqrt(1 + 8 * it->second) - 1) / 2;
  }

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