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

#include <bits/stdc++.h>
using namespace std;
#define ll long
#define ld long double
#define eps 1e-9
#define maxp 11040000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld", &s);
#define sout(s) printf("%lld\\n", s);
#define in(s) cin >> s
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define vll vector<ll>
#define out(s) cout << s
#define outs(s, a) cout << s << a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false), cin.tie(0)
#define nfl(i, n) for (i = 0; i < n; i++)
#define sfl(i, s, e) for (i = s; i < e; i++)
#define ufl(i, n) for (i = n - 1; i >= 0; i--)
ll freq[maxp];
ll power(ll x, ll y) {
  ll ret = 1;
  while (y > 0) {
    if (y & 1)
      ret = (ret * x);
    y /= 2;
    x = (x * x);
  }
  return ret;
}
void pf(ll n) {
  while (n % 2 == 0) {
    freq[2]++;
    n /= 2;
  }
  for (ll i = 3; i * i <= n; i += 2) {

    if (n % i == 0) {
      ll lo = 1, hi = n, mid;
      ll ans = 0;
      while (lo <= hi) {
        mid = (lo + hi) / 2;
        ll val = power(i, mid);
        if (n % val == 0) {
          ans = mid;
          lo = mid + 1;
        } else {
          hi = mid - 1;
        }
      }
      n /= power(i, ans);
      freq[i] = ans;
    }
  }
  if (n > 2) {
    freq[0]++;
  }
}
ll sm(ll n) { return (n * (n + 1)) / 2; }
ll get(ll n) {
  ll sq = sqrt(1 + 8 * n);
  return (sq - 1) / 2;
}
void solve() {
  ll n, i;
  in(n);
  memset(freq, 0, sizeof freq);
  pf(n);
  ll ans = 0;
  for (i = 0; i < maxp; i++) {
    if (freq[i]) {
      ans += get(freq[i]);
    }
  }
  cout << ans << '\\n';
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  clock_t t1 = clock();
  gear_change;
  ll test = 1;
  // in(test);
  while (test--) {
    solve();
  }
  clock_t t2 = clock();
  cerr << "Time elapsed:- " << (double)(t2 - t1) / CLOCKS_PER_SEC << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long
#define ld long double
#define eps 1e-9
#define maxp 1104000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld", &s);
#define sout(s) printf("%lld\\n", s);
#define in(s) cin >> s
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define vll vector<ll>
#define out(s) cout << s
#define outs(s, a) cout << s << a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false), cin.tie(0)
#define nfl(i, n) for (i = 0; i < n; i++)
#define sfl(i, s, e) for (i = s; i < e; i++)
#define ufl(i, n) for (i = n - 1; i >= 0; i--)
ll freq[maxp];
ll pf(ll n) {
  while (n % 2 == 0) {
    freq[2]++;
    n /= 2;
  }
  for (ll i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      freq[i]++;
      n /= i;
    }
  }
  if (n > 2) {
    freq[0]++;
  }
}
ll sm(ll n) { return (n * (n + 1)) / 2; }
ll get(ll n) {
  ll sq = sqrt(1 + 8 * n);
  return (sq - 1) / 2;
}
void solve() {
  ll n, i;
  in(n);
  memset(freq, 0, sizeof freq);
  pf(n);
  ll ans = 0;
  if (freq[0]) {
    cout << "1\\n";
    return;
  }
  for (i = 1; i < maxp; i++) {
    if (freq[i]) {
      ans += get(freq[i]);
    }
  }
  cout << ans << '\\n';
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  clock_t t1 = clock();
  gear_change;
  ll test = 1;
  // in(test);
  while (test--) {
    solve();
  }
  clock_t t2 = clock();
  cerr << "Time elapsed:- " << (double)(t2 - t1) / CLOCKS_PER_SEC << '\\n';
}