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

/*input
1
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i, n) for (int i = 1; i <= n; i++)
#define RED(i, n) for (int i = n; i > 0; i--)
#define REPS(i, n) for (int i = 1; (i * i) <= n; i++)
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FORD(i, a, b) for (int i = a; i >= b; i--)

#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr)                                                             \\
  for (auto it = arr.begin(); it != arr.end(); ++it)                           \\
    cout << *it << " ";                                                        \\
  cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x, y) cout << x << " " << y << endl;
#define debug3(x, y, z) cout << x << " " << y << " " << z << endl;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const int INF = 1e18 + 1;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;

int raise(int a, int n, int m = MOD) {
  if (n == 0)
    return 1;
  if (n == 1)
    return a;
  int x = 1;
  x *= raise(a, n / 2, m);
  x %= m;
  x *= x;
  x %= m;
  if (n % 2)
    x *= a;
  x %= m;
  return x;
}

int floor1(int n, int k) {
  if (n % k == 0 || n >= 0)
    return n / k;
  return (n / k) - 1;
}

int ceil1(int n, int k) { return floor1(n + k - 1, k); }

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  int x = n;
  for (int i = 2; i * i <= x; i++) {
    if (n % i == 0) {
      int cur = 0;
      while (n % i == 0) {
        cur++;
        n /= i;
      }
      int fir = 1;
      int all = 0;
      while (all + fir <= cur) {
        all += fir;
        ans++;
        fir++;
      }
    }
  }
  if (n > 1)
    ans++;
  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

// please refer from line no. 207
/////*31022618*/////
//_MONU KUMAR
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define tc                                                                     \\
  ll t = 1;                                                                    \\
  cin >> t;                                                                    \\
  while (t--)
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pll pair<ll, ll>
#define vll std::vector<ll>
#define vpll vector<pll>
#define mll std::map<ll, ll>
#define mpll                                                                   \\
  std:                                                                         \\
  map<pll, ll>
#define p1(x) cout << x << "\\n";
#define p2(x, y) cout << x << " " << y << "\\n";
#define p3(x, y, z) cout << x << " " << y << " " << z << "\\n";
#define p4(x, y, z, w) cout << x << " " << y << " " << z << " " << w << "\\n";
#define trace(x)                                                               \\
  cout << #x << ": " << x << " "                                               \\
       << "\\n";
#define trace2(x, y)                                                           \\
  cout << #x << ": " << x << " | " << #y << ": " << y << "\\n";
#define trace3(x, y, z)                                                        \\
  cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << "\\n";
#define trace4(a, b, c, d)                                                     \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << "\\n";
#define nL cout << "\\n";
#define lp(i, l, r) for (long long int i = l; i < r; i++)
#define lpr(i, r, l) for (long long int i = r - 1; i >= l; i--)
#define mem(a, x) memset(a, x, sizeof(a)) // set elements of array to some value
#define pi 3.1415926535897932384626
#define mod 1000000007
#define big 1e18
#define small -big
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define ff first
#define ss second
#define siz 256
#define leadzero(a) __builtin_clz(a)      // count leading zeroes
#define trailzero(a) __builtin_ctz(a)     // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits
#define all(v) v.begin(), v.end()
#define lps(v, x) (lower_bound(all(v), x) - v.begin())
#define ups(v, x) (upper_bound(all(v), x) - v.begin())
#define ina(a, n)                                                              \\
  ll a[n];                                                                     \\
  lp(i, 0, n) cin >> a[i];
#define ona(a, n) lp(i, 0, n) cout << a[i] << " ";
// #########################################################################################
bool anagram(char *s1, char *s2) {
  ll count[siz];
  mem(count, 0);
  ll i;
  for (i = 0; s1[i] && s2[i]; i++) {
    count[s1[i]]++;
    count[s2[i]]--;
  }
  if (s1[i] || s2[i]) {
    return false;
  }
  lp(i, 0, siz) {
    if (count[i]) {
      return false;
    }
  }
  return true;
}
// ###########################################################################################
//  modulo Multiplication
ll moduloMultiplication(ll a, ll b, ll zz) {
  ll res = 0;
  a %= mod;
  while (b) {
    if (b & 1)
      res = (res + a) % zz;

    a = (2 * a) % zz;

    b >>= 1;
  }
  return res;
}
// ###########################################################################################

ll convert(string s) {
  bool o = true;
  ll ans = 0;
  for (ll i = 0; i < s.length(); i++) {
    ans = ans * 10 + (s[i] - 48);
  }
  return ans;
}
// ###########################################################################################
// function to calculate a^b under mod...
ll powmod(ll a, ll b, ll modulo) {
  if (b == 0 || a == 1)
    return 1;
  ll half = powmod(a, (b / 2), modulo) % modulo;
  ll full = (half * half) % modulo;

  if (b % 2)
    return (full * a) % modulo;
  return full % modulo;
}
// ###########################################################################################
// function to calculate inverse modulo under mod...assuming gcd is 1
ll invmod(ll a, ll modulo) {
  ll check = powmod(a, modulo - 2, modulo) % modulo;
  return check;
}
// ###########################################################################################

ll max(ll a, ll b) {
  if (a > b) {
    /* code */
    return a;
  }
  return b;
}
// ###########################################################################################
ll min(ll a, ll b) {
  if (a < b) {
    /* code */
    return a;
  }
  return b;
}
// ###########################################################################################
ll minn(ll a, ll b, ll c) {
  if (a < b) {
    /* code */
    return min(a, c);
  } else {
    return min(b, c);
  }
}
// ###########################################################################################
ll maxx(ll a, ll b, ll c) {
  if (a < b) {
    /* code */
    return max(b, c);
  } else {
    return max(a, c);
  }
}
// ###########################################################################################
ll min(ll a, int b) {
  if (a < b)
    return a;
  return b;
}
// ###########################################################################################
ll min(int a, ll b) {
  if (a < b)
    return a;
  return b;
}
// ###########################################################################################
ll max(ll a, int b) {
  if (a > b)
    return a;
  return b;
}
// ###########################################################################################
ll max(int a, ll b) {
  if (a > b)
    return a;
  return b;
}
// ###########################################################################################
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// ###########################################################################################
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// ###########################################################################################
void yes() {
  cout << "YES"
       << "\\n";
}
// ###########################################################################################
void no() {
  cout << "NO"
       << "\\n";
}
// ###########################################################################################
int main() {
  fast
      //  clock_t launch=clock();
      //  string r = s1.substr(1, 3);
      //  while(clock()<CLOCKS_PER_SEC*10)
      //  using num = modnum<int(1e9)+7>;
      //  num len = s.size();
      //  double PI= 2 * acos(0.0); or M_PI
      int n;
  cin >> n;
  int ans = 0;
  int x = n;
  for (int i = 2; i * i <= x; i++) {
    if (n % i == 0) {
      int cur = 0;
      while (n % i == 0) {
        cur++;
        n /= i;
      }
      int fir = 1;
      int all = 0;
      while (all + fir <= cur) {
        all += fir;
        ans++;
        fir++;
      }
    }
  }
  if (n > 1)
    ans++;
  cout << ans;

  // clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\\n";
  return 0;
}
//////////*********************end of program*********************//////////