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

#include <algorithm>
#include <bits/stdc++.h>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...)                                                                \\
  show(__VA_ARGS__);                                                           \\
  cout << endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head, class... Args> void show(Head t, Args... args) {
  std::cout << t << " ";
  show(args...);
}
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define REPR1(i, n) for (ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for (ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type, A, N) vector<type> A(N)
#define VECi(type, A, N, i) vector<type> A(N, i)
#define VEC2(type, A, N, M) vector<vector<type>> A(N, vector<type>(M))
#define VEC2i(type, A, N, M, i) vector<vector<type>> A(N, vector<type>(M, i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k) {
  int s = 1;
  for (ll i = 1; i <= k; ++i)
    s *= i;
  return s;
}
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll antidiv(ll N, ll C, ll D) {
  return N - floor(N / C) - floor(N / D) + floor(N / lcm(C, D));
}
vector<ll> yakusuu(ll N) {
  vector<ll> ret;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ret.push_back(i);
      if (i * i != N)
        ret.push_back(N / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
vector<ll> getPrime(ll N) {
  vector<ll> p = {2};
  for (ll i = 2; i * i <= N; i++) {
    for (ll j = 0; j <= p.size(); j++) {
    }
  }
  return p;
}
bool isp(ll N) {
  if (N == 1)
    return false;
  for (ll i = 2; i * i <= N; i++) {
    if (N % i == 0)
      return false;
  }
  return true;
}
int main() {
  ll N;
  cin >> N;

  if (N == 1) {
    cout << 0;
    return 0;
  }
  ll soi;

  ll ii;
  ll cnt = 0;
  for (ii = 2; ii < sqrt(N); ii++) {
    if (N % ii == 0) {
      soi = 0;
      while (true) {
        if (N % ii == 0) {
          N /= ii;
          soi++;
        } else
          break;
      }
      // sl(ii,soi[ii],N)
      ll t = soi;
      for (ll j = 1;; j++) {
        if (t >= j) {
          t -= j;
          cnt++;
        } else
          break;
      }
    }
  }
  // sl(N)
  if (N != 1)
    cnt++;
  cout << cnt;
  // cout<<fixed<<setprecision(32)<<m;
  // sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
  // if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...)                                                                \\
  show(__VA_ARGS__);                                                           \\
  cout << endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head, class... Args> void show(Head t, Args... args) {
  std::cout << t << " ";
  show(args...);
}
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define REPR1(i, n) for (ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for (ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type, A, N) vector<type> A(N)
#define VECi(type, A, N, i) vector<type> A(N, i)
#define VEC2(type, A, N, M) vector<vector<type>> A(N, vector<type>(M))
#define VEC2i(type, A, N, M, i) vector<vector<type>> A(N, vector<type>(M, i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k) {
  int s = 1;
  for (ll i = 1; i <= k; ++i)
    s *= i;
  return s;
}
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll antidiv(ll N, ll C, ll D) {
  return N - floor(N / C) - floor(N / D) + floor(N / lcm(C, D));
}
vector<ll> yakusuu(ll N) {
  vector<ll> ret;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ret.push_back(i);
      if (i * i != N)
        ret.push_back(N / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
vector<ll> getPrime(ll N) {
  vector<ll> p = {2};
  for (ll i = 2; i * i <= N; i++) {
    for (ll j = 0; j <= p.size(); j++) {
    }
  }
  return p;
}
bool isp(ll N) {
  if (N == 1)
    return false;
  for (ll i = 2; i * i <= N; i++) {
    if (N % i == 0)
      return false;
  }
  return true;
}
int main() {
  ll N;
  cin >> N;

  if (N == 1) {
    cout << 0;
    return 0;
  }
  ll soi;

  ll ii;
  ll cnt = 0;
  for (ii = 2; ii < sqrt(N); ii++) {
    if (N % ii == 0) {
      soi = 0;
      while (true) {
        if (N % ii == 0) {
          N /= ii;
          soi++;
        } else
          break;
      }
      // sl(ii,soi[ii],N)
      ll t = soi;
      ll o = 1;
      while (t != 0) {
        // sl(t,ii);
        t -= o++;
        cnt++;
      }
    }
  }
  // sl(N)
  if (N != 1)
    cnt++;
  cout << cnt;
  // cout<<fixed<<setprecision(32)<<m;
  // sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
  // if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
  cout << endl;
  return 0;
}