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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ll long long int
#define INF 1000000000
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ff first
#define ss second
#define ps(x, y) fixed << setprecision(y) << x
#define setbits(x)                                                             \\
  __builtin_popcountll(x) // counts no of ones in binary representation
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pi 3.141592653589793238
#define sortt(v) sort(v.begin(), v.end())
#define lb(v, x) std::lower_bound(v.begin(), v.end(), x)
#define ub(v, x) std::upper_bound(v.begin(), v.end(), x)

using namespace std;

int main() {
  ll n, i, a, b, c, ans = 0;
  cin >> n;
  map<ll, ll> ma;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      c = 0;
      while (n % i == 0) {
        c++;
        n /= i;
      }
      ma[i] = c;
    }
  }
  if (n != 1)
    ma[n] = 1;
  for (auto it = ma.begin(); it != ma.end(); it++) {
    b = it->second;
    c = 1;
    while (b >= c) {
      ans++;
      b -= c;
      c++;
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll>
#define pint pair<int, int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 1000000000000000000
#define endl '\\n'
#define mp make_pair
#define INF 1000000000
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ff first
#define ss second
#define ps(x, y) fixed << setprecision(y) << x
#define setbits(x)                                                             \\
  __builtin_popcountll(x) // counts no of ones in binary representation
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pi 3.141592653589793238
#define sortt(v) sort(v.begin(), v.end())
#define lb(v, x) std::lower_bound(v.begin(), v.end(), x)
#define ub(v, x) std::upper_bound(v.begin(), v.end(), x)

using namespace std;

bool isprime(ll n) { // to check whteher no is prime or not
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;

  // This is checked so that we can skip
  // middle five numbers in below loop
  if (n % 2 == 0 || n % 3 == 0)
    return false;

  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;

  return true;
}

int main() {
  fast;
  ll n;
  cin >> n;
  if (isprime(n)) {
    cout << 1;
    return 0;
  }
  map<ll, ll> ma;
  ll cnt, i;
  for (i = 2; i * i <= (n); i++) {
    if (n % i == 0) {
      cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      ma[i] = cnt;
    }
  }
  if (n != 1)
    ma[n] = 1;
  ll ans = 0;
  ll temp, c;
  // map<ll,ll>::iterator it;
  for (auto it = ma.begin(); it != ma.end(); it++) {
    temp = it->ss;
    c = 1;
    while (temp >= c) {
      ans++;
      temp -= c;
      c++;
    }
  }
  cout << ans;
}