alexjercan/bugnet huggingface dataset:
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

vector<int> eratos(int n);

int main() {
  ll n;
  cin >> n;
  vector<int> prime = eratos((int)sqrt((double)n + 9));
  ll cnt = 0;
  ll left = n;
  int ind = 0, p_size = prime.size();
  ll z = prime[0], nowz = prime[0];
  while (left != 1 && ind < p_size) {
    while (true) {
      if (left % nowz != 0) {
        break;
      }
      left /= nowz;
      // cout << left << endl;
      nowz *= z;
      cnt++;
    }
    ind++;
    if (ind == p_size) {
      break;
    }
    z = prime[ind];
    nowz = prime[ind];
  }
  if (left < prime[p_size - 1]) {
    cout << cnt << endl;
  } else {
    cout << cnt + 1 << endl;
  }

  return 0;
}

vector<int> eratos(int n) {
  vector<bool> prime(n, true);
  vector<int> primebox;
  prime[0] = false;
  prime[1] = false;
  rep2(i, 2, n) {
    if (prime[i] == true) {
      primebox.push_back(i);
      int out = i * 2;
      while (out < n) {
        prime[out] = false;
        out += i;
      }
    }
  }
  return primebox;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

vector<int> eratos(int n);

int main() {
  ll n;
  cin >> n;
  vector<int> prime = eratos((int)sqrt((double)n + 9));

  ll cnt = 0;
  ll left = n;
  int ind = 0, p_size = prime.size();
  ll z = prime[0], nowz = prime[0];
  while (left != 1 && ind < p_size) {
    while (true) {
      if (left % nowz != 0) {
        break;
      }
      left /= nowz;
      // cout << left << endl;
      nowz *= z;
      cnt++;
    }
    ind++;
    if (ind == p_size) {
      break;
    }
    z = prime[ind];
    nowz = prime[ind];
  }
  if (left < prime[p_size - 1]) {
    cout << cnt << endl;
  } else {
    cout << cnt + 1 << endl;
  }

  return 0;
}

vector<int> eratos(int n) {
  vector<bool> prime(n, true);
  vector<int> primebox;
  prime[0] = false;
  prime[1] = false;
  rep2(i, 2, n) {
    if (prime[i] == true) {
      primebox.push_back(i);
      int out = i * 2;
      while (out <= n) {
        prime[out] = false;
        out += i;
      }
    }
  }
  return primebox;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define deb(x) cerr << #x << ": " << x << '\\n';
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

vector<ll> primes;
void SieveOfEratosthenes(ll n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));

  for (ll p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (ll i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (ll p = 2; p <= n; p++)
    if (prime[p])
      primes.push_back(p);
}

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

int main() {
  ios;
  ll n;
  cin >> n;
  if (isPrime(n)) {
    cout << 1;
    return 0;
  }
  SieveOfEratosthenes(7e6);
  ll ans = 0, check = 0;
  for (ll i = 0; i < primes.size(); i++) {
    for (ll j = 1; j <= 40; j++) {
      check = pow(primes[i], j);
      if (n % check == 0) {
        ans++;
        n /= check;
      }
    }
  }
  if (isPrime(n) && n > 7e6)
    ans++;
  cout << ans;
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define deb(x) cerr << #x << ": " << x << '\\n';
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;
ll n = 50000000;
vector<ll> primes;
bool prime[50000000];
void SieveOfEratosthenes() {
  for (ll p = 2; p * p <= n; p++) {
    if (prime[p] == false) {
      for (ll i = p * p; i <= n; i += p)
        prime[i] = true;
    }
  }
  for (ll p = 2; p <= n; p++)
    if (!prime[p])
      primes.push_back(p);
}

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

int main() {
  ios;
  ll N;
  cin >> N;
  ll ans = 0;
  if (isPrime(N)) {
    cout << 1;
    return 0;
  }
  SieveOfEratosthenes();
  set<ll> st;
  for (ll i = 0; i < primes.size(); i++) {
    for (ll j = 1; j <= 40; j++) {
      ll check = pow(primes[i], j);
      if (N % check == 0) {
        ans++;
        N /= check;
      }
    }
  }
  if (ans == 1)
    ans++;
  cout << ans;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

#define INF 1000005

long long N;
bool isPrime[INF];
vector<int> primes;
int ans;

int main() {
  scanf("%lld", &N);
  for (int i = 2; i <= INF; i++)
    isPrime[i] = true;
  for (long long i = 2; i <= INF; i++) {
    if (isPrime[i]) {
      for (long long j = i * i; j <= INF; j += i) {
        isPrime[j] = false;
      }
    }
  }
  for (long long i = 2; i <= INF; i++) {
    if (isPrime[i])
      primes.push_back(i);
  }
  for (int prime : primes) {
    int cur = prime;
    while (N % cur == 0) {
      // printf("%d\\n", cur);
      ans++;
      N /= cur;
      cur *= prime;
    }
    if (N == 1)
      break;
  }
  // printf("%d\\n", N);
  if (N > INF)
    ans++;
  printf("%d\\n", ans);
  return 0;
}
/*
2 * 4 * 3 * 9 * 5 * 25 * 6079
*/


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <set>

using namespace std;

#define INF 200000005

long long N;
bool isPrime[INF];
set<int> primes;
int ans;

int main() {
  scanf("%lld", &N);
  for (int i = 2; i <= INF; i++)
    isPrime[i] = true;
  for (long long i = 2; i <= INF; i++) {
    if (isPrime[i]) {
      for (long long j = i * i; j <= INF; j += i) {
        isPrime[j] = false;
      }
    }
  }
  for (long long i = 2; i <= INF; i++) {
    if (!isPrime[i])
      continue;
    long long cur = i;
    while (cur <= INF) {
      primes.insert(cur);
      cur *= i;
    }
  }
  for (int prime : primes) {
    if (N % prime == 0) {
      // printf("%d\\n", prime);
      ans++;
      N /= prime;
    }
    if (N == 1)
      break;
  }
  if (ans == 0)
    printf("%d\\n", N == 1 ? 0 : 1);
  else
    printf("%d\\n", ans);
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define task "MAXFRAME"

#define nguyen_dz the_best
#define ll long long
#define ld long double
#define pb push_back
#define endl "\\n"
#define ff first
#define ss second
#define pll pair<ll, ll>
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;

using namespace std;
const ll maxn = 4e6 + 100;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("test.txt","r",stdin);
  if (fopen(task ".INP", "r")) {
    freopen(task ".INP", "r", stdin);
    freopen(task ".OUT", "w", stdout);
  }
  ll n;
  cin >> n;
  ll ans = 0;
  for (long long i = 2; i * i <= n; i++) {

    if (n % i == 0) {
      ll cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      ll res = cnt;
      ll l = 1, h = 1e8;
      while (l <= h) {
        ll m = (l + h) / 2;
        if (m * (m + 1) / 2 > res)
          h = m - 1;
        else
          l = m + 1;
      }
      ans += h;
    }
  }
  if (n > 1)
    ans++;

  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define task "MAXFRAME"

#define nguyen_dz the_best
#define ll long long
#define ld long double
#define pb push_back
#define endl "\\n"
#define ff first
#define ss second
#define pll pair<ll, ll>
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;

using namespace std;
const ll maxn = 4e6 + 100;

map<ll, ll> cnt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("test.txt","r",stdin);
  if (fopen(task ".INP", "r")) {
    freopen(task ".INP", "r", stdin);
    freopen(task ".OUT", "w", stdout);
  }
  ll n;
  cin >> n;
  for (int i = 2; i * i <= n; i++) {

    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
        cnt[i]++;
      }
    }
  }
  if (n > 1)
    cnt[n]++;
  ll ans = 0;
  for (auto p : cnt) {
    ll res = p.ss;
    ll l = 1, h = 1e8;
    while (l <= h) {
      ll m = (l + h) / 2;
      if (m * (m + 1) / 2 > res)
        h = m - 1;
      else
        l = m + 1;
    }
    ans += h;
  }
  cout << ans;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 1e9 + 5;
const ll INF = 1e18;
using P = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  ll n, ans = 0, cnt, y;
  cin >> n;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      y = 1;
      for (int i = 1; i <= cnt; i++) {
        ans++;
        cnt -= i;
      }
    }
  }
  if (n > 1) {
    ans++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 1e9 + 5;
const ll INF = 1e18;
using P = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  ll n, ans = 0, cnt = 0;
  cin >> n;
  vector<ll> v;
  bool f[1000005] = {}, x[1000005] = {};
  for (ll i = 2; i <= 1000000; i++) {
    if (!f[i]) {
      v.push_back(i);
      for (ll j = i * 2; j <= 1000000; j += i) {
        f[j] = true;
      }
    }
  }
  for (auto p : v) {
    for (ll j = 2; j <= 1000000; j++) {
      if (pow(p, j) > 1000000) {
        break;
      } else {
        v.push_back(pow(p, j));
      }
    }
  }
  sort(v.begin(), v.end());
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int c1 = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      c1++;
    }
  }
  if (c1 == 0) {
    cout << 1 << endl;
    return 0;
  }
  while (n != 1 && cnt != v.size()) {
    if (n % v[cnt] == 0) {
      x[v[cnt]] = true;
      n /= v[cnt];
      ans++;
    }
    cnt++;
  }
  if (n != 1 && !x[n]) {
    ans++;
  }
  cout << ans << endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

typedef long long LL;

// Find the biggest m that m(m+1)/2 <= n. (1+2+...+(m-1)+m <= n)
LL calc(LL n) {
  n <<= 1LL;
  LL x = __builtin_sqrt(n);
  if (x * (x + 1LL) > n)
    return x - 1LL;
  if ((x + 1LL) * (x + 2LL) <= n)
    return x + 1LL;
  return x;
}

int main(int argc, char **argv) {
  LL n, ans = 0LL;
  scanf("%lld", &n);
  bool isprime = true;
  int t = __builtin_sqrt(n);
  for (LL i = 2LL; i <= t; i++) {
    LL cnt = 0LL;
    while (n % i == 0LL)
      n /= i, cnt++;
    if (cnt > 0LL)
      ans += calc(cnt), isprime = false;
  }
  if (n > 1LL)
    if (isprime)
      puts("1");
    else
      printf("%lld\\n", ans += 1);
  else
    printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

typedef long long LL;

// Find the biggest m that m(m+1)/2 <= n. (1+2+...+(m-1)+m <= n)
LL calc(LL n) {
  n <<= 1LL;
  LL x = __builtin_sqrt(n);
  if (x * (x + 1LL) > n)
    return x - 1LL;
  if ((x + 1LL) * (x + 2LL) <= n)
    return x + 1LL;
  return x;
}

int main(int argc, char **argv) {
  LL n, ans = 0LL;
  scanf("%lld", &n);
  for (LL i = 2LL; i <= n; i++) {
    LL cnt = 0LL;
    while (n % i == 0LL)
      n /= i, cnt++;
    if (cnt > 0LL)
      ans += calc(cnt);
  }
  if (n > 1LL)
    puts("1"); // n is prime
  else
    printf("%lld\\n", ans);
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(long n) {
  long result = 0;
  for (long i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;

    for (int j = 1; n % i == 0; ++j) {
      bool ok = true;
      for (int k = 0; k < j; ++k) {
        if (n % i != 0) {
          ok = false;
          break;
        }
        n /= i;
      }
      if (!ok)
        break;
      ++result;
    }
  }

  if (n != 1)
    ++result;

  return result;
}

int main() {
  long n;
  std::cin >> n;

  std::cout << std::setprecision(20);
  std::cout << solve(n) << std::endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(long n) {
  long result = 0;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;

    for (int j = 1; n % i == 0; ++j) {
      bool ok = true;
      for (int k = 0; k < j; ++k) {
        if (n % i != 0) {
          ok = false;
          break;
        }
        n /= i;
      }
      if (!ok)
        break;
      ++result;
    }
  }

  if (n != 1)
    ++result;

  return result;
}

int main() {
  long n;
  std::cin >> n;

  std::cout << std::setprecision(20);
  std::cout << solve(n) << std::endl;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// template
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;
const double eps = 1e-12;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// end

int main() {
  ll n;
  cin >> n;
  int res = 0;
  vector<int> pw;
  for (ll p = 2; p * p <= n; p++)
    if (n % p == 0) {
      pw.push_back(0);
      while (n % p == 0) {
        n /= p;
        pw.back()++;
      }
    }
  if (n != 1)
    pw.push_back(1);
  for (int x : pw) {
    int add = 0;
    while (add * (add + 1) / 2 <= x)
      add++;
    res += add - 1;
  }
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

// template
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;
const double eps = 1e-12;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// end

typedef pair<ll, ll> P;
int res = 0;
set<ll> used;
void dfs(ll n, int cur) {
  chmax(res, cur);
  if (n == 1)
    return;
  ll m = n;
  vector<P> cand;
  for (ll p = 2; p * p <= n; p++)
    if (n % p == 0) {
      cand.push_back({p, 0});
      while (n % p == 0) {
        n /= p;
        cand.back().second++;
      }
    }
  if (n != 1)
    cand.push_back({n, 1});
  for (auto [p, c] : cand) {
    ll d = 1;
    rep(i, 1, c + 1) {
      d *= p;
      if (!used.count(d)) {
        used.insert(d);
        dfs(m / d, cur + 1);
        used.erase(d);
      }
    }
  }
}

int main() {
  ll n;
  cin >> n;
  dfs(n, 0);
  cout << res << endl;
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> using v2 = vector<vector<T>>;
template <typename T> inline v2<T> fill(int r, int c, T t) {
  return v2<T>(r, vector<T>(c, t));
}

int bs(int sum) {
  int lo = 0;
  int hi = sum;
  int ans = -1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (mid * (mid + 1) <= 2 * sum) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  return ans;
}
ll n;
void solve() {
  cin >> n;
  if (n == 1) {
    cout << 0 << '\\n';
    return;
  }
  vector<ll> factors;
  ll s = sqrt(n);
  int ans = 0;
  for (int i = 2; i <= s; i++) {
    if (n % i == 0)
      factors.push_back(i);
    if ((ll)i * (ll)(n / i) == n && n % (n / i) == 0)
      factors.push_back(n / i);
  }
  factors.push_back(n);

  sort(factors.begin(), factors.end());

  for (ll i : factors) {
    // cout << i << " ";
    int times = 0;
    while (n % i == 0) {
      n /= i;
      times++;
    }
    ans += bs(times);
  } // cout << '\\n';

  cout << ans << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> using v2 = vector<vector<T>>;
template <typename T> inline v2<T> fill(int r, int c, T t) {
  return v2<T>(r, vector<T>(c, t));
}

int bs(int sum) {
  int lo = 0;
  int hi = sum;
  int ans = -1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (mid * (mid + 1) <= 2 * sum) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  return ans;
}
ll n;
void solve() {
  cin >> n;
  if (n == 1) {
    cout << 0 << '\\n';
    return;
  }
  vector<ll> factors;
  ll s = sqrt(n);
  int ans = 0;
  for (int i = 2; i <= s; i++) {
    if (n % i == 0)
      factors.push_back(i);
    if ((ll)i * (ll)(n / i) == n && n % (n / i) == 0)
      factors.push_back(n / i);
  }
  factors.push_back(n);

  sort(factors.begin(), factors.end());

  for (int i : factors) {
    // cout << i << " ";
    int times = 0;
    while (n % i == 0) {
      n /= i;
      times++;
    }
    ans += bs(times);
  } // cout << '\\n';

  cout << ans << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded


/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */

#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d", &n)
#define lscf(n) scanf("%lld", &n)
#define lpri(n) printf("%lld ", n)
#define pri(n) printf("%d ", (int)n)
#define prin(n) printf("%d\\n", (int)n)
#define lprin(n) printf("%lld\\n", n)
#define rep(i, ini, n) for (int i = ini; i < (int)n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define tc                                                                     \\
  int tt;                                                                      \\
  scf(tt);                                                                     \\
  while (tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 3;

int main() {

  ll n;
  lscf(n);

  ll ans = 0;

  for (ll i = 2; i * i < n; i++) {

    if (n % i == 0) {

      ll ctr = 0;

      while (n % i == 0) {
        n /= i;
        ctr++;
      }

      ll st = 1;

      while (ctr >= st) {
        ans++;
        ctr -= st;
        st++;
      }
    }
  }

  if (n > 1)
    ans++;

  lprin(ans);
}

Error: TLE

Fixed submission:


/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */

#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d", &n)
#define lscf(n) scanf("%lld", &n)
#define lpri(n) printf("%lld ", n)
#define pri(n) printf("%d ", (int)n)
#define prin(n) printf("%d\\n", (int)n)
#define lprin(n) printf("%lld\\n", n)
#define rep(i, ini, n) for (int i = ini; i < (int)n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define tc                                                                     \\
  int tt;                                                                      \\
  scf(tt);                                                                     \\
  while (tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 3;

int a[N], ctr[N];

int main() {

  ll n, ans = 0;
  lscf(n);

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

    if (n % i == 0) {

      int ctr = 0, st = 1;

      while (n % i == 0)
        n /= i, ctr++;

      while (ctr - st >= 0) {
        ans++;
        ctr -= st;
        st++;
      }
    }
  }

  if (n > 1)
    ans++;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ll n;
  cin >> n;
  map<int, int> m;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      m[i]++;
      n /= i;
    }
  }
  if (n != 1)
    m[n] = 1;
  int ans = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    int num = itr->second;
    int count = 1;
    while (true) {
      num -= count;
      count++;
      if (num >= 0)
        ans++;
      else
        break;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ll n;
  cin >> n;
  map<int, int> m;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      m[i]++;
      n /= i;
    }
  }
  if (n != 1)
    m[n] = 1;
  int ans = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    int num = itr->second;
    int count = 1;
    while (true) {
      num -= count;
      count++;
      if (num >= 0)
        ans++;
      else
        break;
    }
  }
  cout << ans << endl;
}