Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\\n'
#define X first
#define Y second
#define nimble                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define _sz(x) (int)x.size()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repv(v) for (int i = 0; i < _sz(v); i++)
#define rep1(i, b, a) for (int i = b; i >= a; i--)
#define preci(x) fixed << setprecision(x)
#define tc                                                                     \\
  int tt = 1;                                                                  \\
  cin >> tt;                                                                   \\
  while (tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << nl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#endif

int inf = 0x3f3f3f3f;
ll infl = 0x3f3f3f3f3f3f3f3fLL;
ld infd = 1.0 / 0.0;
const ll MOD = 1e9 + 7; // 998244353 // = (119<<23)+1
const ld pi = 2 * acos(0.0);

ll modi(ll a, ll n) {
  ll x = 1;
  while (n) {
    if (n & 1)
      x *= a;
    n >>= 1;
    a *= a;
  }
  return x;
}

int main() {
  nimble ll n;
  cin >> n;
  ll xd = n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  vector<ll> div;
  for (ll i = 2; i * i <= n; i++) {
    int f = 0;
    while (n % i == 0) {
      n /= i;
      f = 1;
    }
    if (f)
      div.pb(i);
  }
  if (n > 1)
    div.pb(n);
  int as = 0;
  for (int i = 0; i < _sz(div); i++) {
    ll x = div[i];
    int cnt = 0;
    ll g = x;
    while (xd % g == 0) {
      cnt++;
      if (xd % g == 0)
        xd /= g;
      else
        break;
      if (xd == 0)
        break;
      g *= x;
    }
    as += cnt;
  }
  cout << as << nl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\\n'
#define X first
#define Y second
#define nimble                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define _sz(x) (int)x.size()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repv(v) for (int i = 0; i < _sz(v); i++)
#define rep1(i, b, a) for (int i = b; i >= a; i--)
#define preci(x) fixed << setprecision(x)
#define tc                                                                     \\
  int tt = 1;                                                                  \\
  cin >> tt;                                                                   \\
  while (tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << nl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#endif

int inf = 0x3f3f3f3f;
ll infl = 0x3f3f3f3f3f3f3f3fLL;
ld infd = 1.0 / 0.0;
const ll MOD = 1e9 + 7; // 998244353 // = (119<<23)+1
const ld pi = 2 * acos(0.0);

ll modi(ll a, ll n) {
  ll x = 1;
  while (n) {
    if (n & 1)
      x *= a;
    n >>= 1;
    a *= a;
  }
  return x;
}

int main() {
  nimble ll n;
  cin >> n;
  ll xd = n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  vector<ll> div;
  for (int i = 2; i * i <= n; i++) {
    int f = 0;
    while (n % i == 0) {
      n /= i;
      f = 1;
    }
    if (f)
      div.pb(i);
  }
  if (n > 1)
    div.pb(n);
  sort(all(div));
  int as = 0;
  for (int i = 0; i < _sz(div); i++) {
    ll x = div[i];
    int cnt = 0;
    ll g = x;
    while (xd % g == 0) {
      cnt++;
      if (xd % g == 0)
        xd /= g;
      else
        break;
      if (xd == 0)
        break;
      g *= x;
    }
    as += cnt;
  }
  cout << as << nl;
  return 0;
}