Problem p02660 (C++)

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(), (x).end()
#define uniq(x) ((x).erase(unique(all(x)), (x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL // compile with -DLOCAL
#define debug(x)                                                               \
  cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define debug_vec(x)                                                           \
  cerr << "LINE" << __LINE__ << " : " << #x << " = ";                          \
  rep(i, sz(x)) { cerr << x[i] << " "; }                                       \
  cerr << endl
#define debug_mat(x)                                                           \
  cerr << "LINE" << __LINE__ << " : " << #x << " = " << endl;                  \
  rep(i, sz(x)) {                                                              \
    rep(j, sz(x[i])) { cerr << x[i][j] << " "; }                               \
    cerr << endl;                                                              \
  }                                                                            \
  cerr << endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;

  int ans = 0;
  for (int i = 2; i * i <= N; i++) {
    if (N % i != 0)
      continue;
    int cnt = 0;
    while (N % i == 0) {
      N /= i;
      cnt++;
    }
    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;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(), (x).end()
#define uniq(x) ((x).erase(unique(all(x)), (x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL // compile with -DLOCAL
#define debug(x)                                                               \
  cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define debug_vec(x)                                                           \
  cerr << "LINE" << __LINE__ << " : " << #x << " = ";                          \
  rep(i, sz(x)) { cerr << x[i] << " "; }                                       \
  cerr << endl
#define debug_mat(x)                                                           \
  cerr << "LINE" << __LINE__ << " : " << #x << " = " << endl;                  \
  rep(i, sz(x)) {                                                              \
    rep(j, sz(x[i])) { cerr << x[i][j] << " "; }                               \
    cerr << endl;                                                              \
  }                                                                            \
  cerr << endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;

  int ans = 0;
  for (ll i = 2; i * i <= N; i++) {
    if (N % i != 0)
      continue;
    int cnt = 0;
    while (N % i == 0) {
      N /= i;
      cnt++;
    }
    for (int j = 1; j <= cnt; j++) {
      ans++;
      cnt -= j;
    }
  }
  if (N != 1)
    ans++;
  cout << ans << endl;

  return 0;
}