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

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i = k; i < (ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(), v.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define DEBUG_VLL(vec)                                                         \\
  REP(sz, vec.size())                                                          \\
      std::cerr << vec[sz] << (sz == vec.size() - 1 ? '\\n' : ' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vll accm = {0};
  for (ll i = 1; i <= 100; i++) {
    accm.emplace_back(accm.back() + i);
  }
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    ll tmp = 0;
    if (n % i == 0) {
      while (n % i == 0) {
        tmp++;
        n /= i;
      }
      ll num = lower_bound(ALL(accm), tmp + 1) - accm.begin();
      // cout << num << '\\n';
      ans += num - 1;
    }
  }
  if (n > 1)
    ans++;
  cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i = k; i < (ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(), v.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define DEBUG_VLL(vec)                                                         \\
  REP(sz, vec.size())                                                          \\
      std::cerr << vec[sz] << (sz == vec.size() - 1 ? '\\n' : ' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vll accm = {0};
  for (ll i = 1; i <= 100; i++) {
    accm.emplace_back(accm.back() + i);
  }
  int ans = 0;
  for (int i = 2; i * i <= n; i++) {
    int tmp = 0;
    if (n % i == 0) {
      while (n % i == 0) {
        tmp++;
        n /= i;
      }
      int num = lower_bound(ALL(accm), tmp + 1) - accm.begin();
      // cout << num << '\\n';
      ans += num - 1;
    }
  }
  if (n > 1)
    ans++;
  cout << ans << '\\n';
  return 0;
}