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

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

// Minimum Macros
using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define rep(_i, _n) for (ll _i = 0; _i < _n; ++_i)
#define rep2(_i, _s, _n) for (ll _i = _s; _i < _n; ++_i)
#define elif else if
// Vector Macros
#define vec vector
#define append(_x) push_back(_x)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n)                                                   \\
  vec<int> _name(_n);                                                          \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecL(_name, _n)                                                   \\
  vec<long> _name(_n);                                                         \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecLL(_name, _n)                                                  \\
  vec<ll> _name(_n);                                                           \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecUL(_name, _n)                                                  \\
  vec<ul> _name(_n);                                                           \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecULL(_name, _n)                                                 \\
  vec<ull> _name(_n);                                                          \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecS(_name, _n)                                                   \\
  vec<string> _name(_n);                                                       \\
  rep(_i, _n) cin >> _name[_i];
#define maxIdx(_name)                                                          \\
  distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec)                                                         \\
  cout << "{";                                                                 \\
  rep(i, _vec.size() - 1) cout << _vec[i] << ",";                              \\
  cout << _vec[_vec.size() - 1];                                               \\
  cout << "}\\n";
// Graph Macros
using Graph = vec<vec<long>>;
inline vec<long> BFS(Graph _g, long start) {
  vec<long> _ans(_g.size(), -1);
  _ans[start] = 0;
  queue<long> _que;
  _que.push(start);
  while (!_que.empty()) {
    long _target = _que.front();
    _que.pop();
    for (long _towhere : _g[_target]) {
      if (_ans[_towhere] == -1) {
        _ans[_towhere] = _ans[_target] + 1;
        _que.push(_towhere);
      }
    }
  }
  return _ans;
}

int main() {
  ull N;
  cin >> N;
  ull buf1 = 1, buf2 = 0;
  ull ans = 0;
  ull last = 2;
  if (N == 1) {
    cout << "0" << endl;
    return 0;
  }
  for (ull i = 2; i * i <= N;) {
    if (N % i == 0) {
      last = i;
      N /= i;
      buf2++;
      if (buf2 >= buf1) {
        buf2 = 0;
        buf1++;
        ans++;
      }
    } else {
      buf1 = 1;
      buf2 = 0;
      i++;
    }
  }
  if (last == N) {
    buf2++;
    if (buf2 >= buf1) {
      buf2 = 0;
      buf1++;
      ans++;
    }
  } else {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

// Minimum Macros
using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define rep(_i, _n) for (ll _i = 0; _i < _n; ++_i)
#define rep2(_i, _s, _n) for (ll _i = _s; _i < _n; ++_i)
#define elif else if
// Vector Macros
#define vec vector
#define append(_x) push_back(_x)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n)                                                   \\
  vec<int> _name(_n);                                                          \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecL(_name, _n)                                                   \\
  vec<long> _name(_n);                                                         \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecLL(_name, _n)                                                  \\
  vec<ll> _name(_n);                                                           \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecUL(_name, _n)                                                  \\
  vec<ul> _name(_n);                                                           \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecULL(_name, _n)                                                 \\
  vec<ull> _name(_n);                                                          \\
  rep(_i, _n) cin >> _name[_i];
#define inputVecS(_name, _n)                                                   \\
  vec<string> _name(_n);                                                       \\
  rep(_i, _n) cin >> _name[_i];
#define maxIdx(_name)                                                          \\
  distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec)                                                         \\
  cout << "{";                                                                 \\
  rep(i, _vec.size() - 1) cout << _vec[i] << ",";                              \\
  cout << _vec[_vec.size() - 1];                                               \\
  cout << "}\\n";
// Graph Macros
using Graph = vec<vec<long>>;
inline vec<long> BFS(Graph _g, long start) {
  vec<long> _ans(_g.size(), -1);
  _ans[start] = 0;
  queue<long> _que;
  _que.push(start);
  while (!_que.empty()) {
    long _target = _que.front();
    _que.pop();
    for (long _towhere : _g[_target]) {
      if (_ans[_towhere] == -1) {
        _ans[_towhere] = _ans[_target] + 1;
        _que.push(_towhere);
      }
    }
  }
  return _ans;
}

int main() {
  ull N;
  cin >> N;
  ull buf1 = 1, buf2 = 0;
  ull ans = 0;
  for (ull i = 2; i <= N;) {
    if (N % i == 0) {
      N /= i;
      buf2++;
      if (buf2 >= buf1) {
        buf2 = 0;
        buf1++;
        ans++;
      }
    } else {
      buf1 = 1;
      buf2 = 0;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}