Problem p02660 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(i, c) ((c).find(i) != (c).end())

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repa(i, a, b) for (int i = (a); i < (b); i++)
#define repd(i, n) for (int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x " = " << x << endl)
#define watch_all(x)                                                           \
  TRACE(cerr << #x " = "; for (auto __i : x) cerr << __i << " "; cerr << endl)

//=========================

void run_test() {
  ll n;
  cin >> n;

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

  ll ans = 0;

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

  cout << ans << endl;
}

//=========================

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // int t = 1, _t; cin >> _t; while(t <= _t) { cout << "Case #" << t++ << ": ";
  // run_test(); } int t; cin >> t; while(t--) run_test();
  run_test();
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(i, c) ((c).find(i) != (c).end())

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repa(i, a, b) for (int i = (a); i < (b); i++)
#define repd(i, n) for (int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x " = " << x << endl)
#define watch_all(x)                                                           \
  TRACE(cerr << #x " = "; for (auto __i : x) cerr << __i << " "; cerr << endl)

//=========================

void run_test() {
  ll n;
  cin >> n;

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

  ll ans = 0;

  for (int i = 2; i <= 1000010; i++) {
    if (n % i == 0) {
      int p = 0;
      while (n % i == 0) {
        n /= i;
        p++;
      }
      int k = 1;
      while (p >= k) {
        p -= k;
        ans++;
        k++;
      }
    }
  }
  if (n > 1)
    ans++;

  cout << ans << endl;
}

//=========================

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // int t = 1, _t; cin >> _t; while(t <= _t) { cout << "Case #" << t++ << ": ";
  // run_test(); } int t; cin >> t; while(t--) run_test();
  run_test();
  return 0;
}