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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define qi queue<int>
#define mii map<int, int>
#define msi map<string, int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep3(i, a, n) for (ll i = (a); i < (n); i++)
#define rep4(i, a, n) for (ll i = (a)-1; i >= n; i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n, 0, sizeof(n));
#define SZ(n) n.size()
#define sn st.nd
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/****************************/
ll n, m, k;
string s;
unsigned long long ans = 1;
int main() {
  cin >> n;
  ll ans = 0;
  if (n == 1) {
    cout << "0";
    return 0;
  }
  ll x = n;
  for (ll i = 2; i * i <= x; i++) {
    int sum = 0;
    while (n % i == 0) {
      n /= i;
      sum++;
    }
    int now = 0;
    while (sum > 0) {
      now++;
      sum -= now;
    }
    if (sum < 0) {
      now--;
    }
    ans += now;
  }
  if (n != 1)
    ans++;
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define qi queue<int>
#define mii map<int, int>
#define msi map<string, int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep3(i, a, n) for (ll i = (a); i < (n); i++)
#define rep4(i, a, n) for (ll i = (a)-1; i >= n; i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n, 0, sizeof(n));
#define SZ(n) n.size()
#define sn st.nd
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/****************************/
ll n, m, k;
string s;
unsigned long long ans = 1;
bool isp[1000010];
bool better[1000010];
int main() {
  cin >> n;
  ll ans = 0;
  if (n == 1) {
    cout << "0";
    return 0;
  }
  ll x = n;
  for (int i = 2; i * i <= x; i++) {
    int sum = 0;
    while (n % i == 0) {
      n /= i;
      sum++;
    }
    int now = 0;
    while (sum > 0) {
      now++;
      sum -= now;
    }
    if (sum < 0) {
      now--;
    }
    ans += now;
  }
  if (n != 1)
    ans++;
  cout << ans;
  return 0;
}