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

#include <bits/stdc++.h>
#include <string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9 + 7)
#define nax (ll)(1e5)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a, n, arr)                                                        \\
  for (int i = a; i < (ll)n; i++)                                              \\
    cout << arr[i] << " ";                                                     \\
  cout << "\\n";
#define check cout << "Working\\n";
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  FIO;

  // Write your code here

  int t = 1;
  // cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll x = n;
    map<ll, ll> mpp;
    for (ll i = 2; i * i <= n; i++) {
      if (x % i == 0) {
        ll cnt = 0;
        while (x % i == 0) {
          x /= i;
          cnt++;
        }
        mpp[i] = cnt;
      }
      if (x == 1)
        break;
    }

    if (x > 1)
      mpp[x] = 1;
    ll cnt = 0;
    for (auto it : mpp) {
      x = it.fi;
      ll lim = it.se;
      for (ll i = 0; i < lim; i++) {
        // cout << n << " " << x << "\\n";
        if (n % x == 0) {
          cnt++;
          n /= x;
        }
        x *= it.fi;
      }
    }
    cout << cnt << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9 + 7)
#define nax (ll)(1e5)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a, n, arr)                                                        \\
  for (int i = a; i < (ll)n; i++)                                              \\
    cout << arr[i] << " ";                                                     \\
  cout << "\\n";
#define check cout << "Working\\n";
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  FIO;

  // Write your code here

  int t = 1;
  // cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll x = n;
    map<ll, ll> mpp;
    for (int i = 2; i * i <= n; i++) {
      if (x % i == 0) {
        int cnt = 0;
        while (x % i == 0) {
          x /= i;
          cnt++;
        }
        mpp[i] = cnt;
      }
      if (x == 1)
        break;
    }

    if (x > 1)
      mpp[x] = 1;
    ll cnt = 0;
    for (auto it : mpp) {
      x = it.fi;
      ll lim = it.se;
      for (int i = 0; i < lim; i++) {
        // cout << n << " " << x << "\\n";
        if (n % x == 0) {
          cnt++;
          n /= x;
        }
        x *= it.fi;
      }
    }
    cout << cnt << "\\n";
  }

  return 0;
}