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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
// #define endl '\\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i, x) for (i = 0; i < x; i++)
#define fs(i, s, x) for (i = s; i < x; i++)
#define fr(i, x, s) for (i = x; i >= s; i--)
#define fit(itr, s) for (itr = s.begin(); itr != s.end(); itr++)
#define W while
#define pp pair<ll, ll>
#define ppi pair<int, int>
#define vl vector<ll>
#define vll vector<pp>
#define vi vector<int>
#define vii vector<ppi>
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define debug(x) cerr << #x << " :: " << x << endl;
#define debug2(x, y)                                                           \\
  cerr << #x << " :: " << x << "\\t" << #y << " :: " << y << endl;
#define debug3(x, y, z)                                                        \\
  cerr << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\t" << #z         \\
       << " :: " << z << endl;
#define debug4(x, y, z, w)                                                     \\
  cerr << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\t" << #z         \\
       << " :: " << z << "\\t" << #w << " :: " << w << endl;
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
const ll MAX = 1e7;
const ll MM = 2e6;
const ll mod = 1e9 + 7;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

ll expo(ll x, ll n, ll M = mod) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = (ans * x) % M;
    }
    x = (x * x) % M;
    n >>= 1;
  }
  return ans;
}
bool pri[MAX];
void sieve() {
  ll i, j;
  fn(i, MAX) pri[i] = 1;
  pri[1] = 0;
  for (i = 2; i * i < MAX; i++) {
    if (pri[i]) {
      for (j = i * i; j < MAX; j += i) {
        pri[j] = 0;
      }
    }
  }
}
void solve() {
  ll n, i, j;
  cin >> n;
  vl tt;
  fs(i, 1, MM) {
    if (pri[i])
      tt.pb(i);
  }
  map<ll, ll> mp;
  fn(i, tt.size()) {
    if (n % tt[i] == 0) {
      mp[tt[i]]++;
      n /= tt[i];
      i--;
    }
  }
  // debug(n);
  if (n > 2)
    mp[n]++;
  map<ll, ll>::iterator itr;
  ll ans = 0;
  for (itr = mp.begin(); itr != mp.end(); itr++) {
    // debug2(itr->fi,itr->se);
    for (j = 1; j < 10000; j++) {
      if ((j * (j + 1)) / 2 > itr->se)
        break;
    }
    // debug2(itr->se,j);
    ans += (j - 1);
  }
  cout << ans;
}

int main() {
  boost;
  ll t = 1;
  // cin>>t;
  sieve();
  while (t--) {
    solve();
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
// #define endl '\\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i, x) for (i = 0; i < x; i++)
#define fs(i, s, x) for (i = s; i < x; i++)
#define fr(i, x, s) for (i = x; i >= s; i--)
#define fit(itr, s) for (itr = s.begin(); itr != s.end(); itr++)
#define W while
#define pp pair<ll, ll>
#define ppi pair<int, int>
#define vl vector<ll>
#define vll vector<pp>
#define vi vector<int>
#define vii vector<ppi>
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define debug(x) cerr << #x << " :: " << x << endl;
#define debug2(x, y)                                                           \\
  cerr << #x << " :: " << x << "\\t" << #y << " :: " << y << endl;
#define debug3(x, y, z)                                                        \\
  cerr << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\t" << #z         \\
       << " :: " << z << endl;
#define debug4(x, y, z, w)                                                     \\
  cerr << #x << " :: " << x << "\\t" << #y << " :: " << y << "\\t" << #z         \\
       << " :: " << z << "\\t" << #w << " :: " << w << endl;
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
const ll MAX = 2e9;
const ll MM = 1e18;
const ll mod = 1e9 + 7;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

ll expo(ll x, ll n, ll M = mod) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = (ans * x) % M;
    }
    x = (x * x) % M;
    n >>= 1;
  }
  return ans;
}

void solve() {
  ll n, i, j;
  cin >> n;
  map<ll, ll> mp;
  for (i = 2; i <= n; i++) {
    if (n % i == 0) {
      mp[i]++;
      n /= i;
      i--;
    }
    for (j = 2; j * j <= n; j++) {
      if (n % j == 0)
        break;
    }
    if (j * j > n) {
      mp[n]++;
      break;
    }
    // debug2(n,i);
  }
  map<ll, ll>::iterator itr;
  ll ans = 0;
  for (itr = mp.begin(); itr != mp.end(); itr++) {
    // debug2(itr->fi,itr->se);
    for (j = 1; j < 10000; j++) {
      if ((j * (j + 1)) / 2 > itr->se)
        break;
    }
    // debug2(itr->se,j);
    ans += (j - 1);
  }
  cout << ans;
}

int main() {
  boost;
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}