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

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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(), (s).end()
#define ALLn(s, n) s, s + n
#define F first
#define S second
#define pb push_back
#define tc(t)                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define D1(x)                                                                  \\
  { cerr << " [" << #x << ": " << x << "]\\n"; }
#define D2(x)                                                                  \\
  {                                                                            \\
    cerr << " [" << #x << ": ";                                                \\
    for (auto it : x)                                                          \\
      cerr << it << " ";                                                       \\
    cerr << "]\\n";                                                             \\
  }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

ll cnt = 0;
map<ll, int> done;

void f(ll n) {
  for (ll p = 2; p * p <= n; ++p) {
    ll e = 0;
    if (n % p)
      continue;
    while (n % p == 0) {
      n /= p;
      ++e;
    }

    ll cur = 1;
    while (cur <= e) {
      cnt++;
      e -= cur;
      cur++;
    }
  }
  if (n > 1) {
    cnt++;
    n /= n;
  }
  // assert(n == 1);
}

void solve() {

  ll n;
  cin >> n;

  f(n);
  cout << cnt;
}

int32_t main() {
  _

#ifndef ONLINE_JUDGE
      freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  // tc(t)
  solve();
}


Error: TLE

Fixed submission:

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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(), (s).end()
#define ALLn(s, n) s, s + n
#define F first
#define S second
#define pb push_back
#define tc(t)                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define D1(x)                                                                  \\
  { cerr << " [" << #x << ": " << x << "]\\n"; }
#define D2(x)                                                                  \\
  {                                                                            \\
    cerr << " [" << #x << ": ";                                                \\
    for (auto it : x)                                                          \\
      cerr << it << " ";                                                       \\
    cerr << "]\\n";                                                             \\
  }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

ll cnt = 0;
map<ll, int> done;

void f(ll n) {
  for (ll p = 2; p * p < n; ++p) {
    ll e = 0;
    while (n % p == 0) {
      n /= p;
      ++e;
    }

    if (e > 0) {
      ll cur = 0;
      map<ll, int> mp;

      while (e > 0) {
        cur++;
        if (e - cur >= 0) {
          e -= cur;
          mp[cur] = 1;
        }
        // else {
        // 	if(mp.count(e-cur)) e=0;
        // 	else cur++;
        // 	break;
        // }
      }
      cnt += cur;
    }
  }
  if (n > 1) {
    cnt++;
    n /= n;
  }
  // assert(n == 1);
}

void solve() {

  ll n;
  cin >> n;

  f(n);
  cout << cnt;
}

int32_t main() {
  _

#ifndef ONLINE_JUDGE
      freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  // tc(t)
  solve();
}