Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
    Author : Nishant Gupta 2.0
*/
#include <bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a, b)                                                             \
  cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a, b, c)                                                          \
  cerr << endl                                                                 \
       << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : "  \
       << c << endl
#define chk4(a, b, c, d)                                                       \
  cerr << endl                                                                 \
       << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : "  \
       << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for (i = a; i < n; i++)
#define rev(i, a, n) for (i = a; i >= n; i--)
#define MSV(A, a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp(int &n) {
  n = 0;
  int ch = getcx();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      sign = -1;
    ch = getcx();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getcx();
  n = n * sign;
}

inline void inp1(LL &n) {
  n = 0;
  LL ch = getcx();
  LL sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      sign = -1;
    ch = getcx();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getcx();
  n = n * sign;
}

int main() {

  LL n;
  cin >> n;

  LL c = n;
  vector<pair<int, int>> v;
  for (int i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (c % i == 0) {
      cnt++;
      c /= i;
    }
    v.PB(MP(i, cnt));
  }

  if (c > 1)
    v.PB(MP(c, 1));

  LL ans = 0;
  for (int i = 0; i < v.size(); i++) {
    int val = v[i].Y;
    int s = 1;
    while (val > 0) {
      if (val - s > s) {
        ans++;
        val -= s;
      } else {
        ans++;
        val = 0;
      }
      s++;
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
/*
    Author : Nishant Gupta 2.0
*/
#include <bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a, b)                                                             \
  cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a, b, c)                                                          \
  cerr << endl                                                                 \
       << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : "  \
       << c << endl
#define chk4(a, b, c, d)                                                       \
  cerr << endl                                                                 \
       << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : "  \
       << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for (i = a; i < n; i++)
#define rev(i, a, n) for (i = a; i >= n; i--)
#define MSV(A, a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp(int &n) {
  n = 0;
  int ch = getcx();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      sign = -1;
    ch = getcx();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getcx();
  n = n * sign;
}

inline void inp1(LL &n) {
  n = 0;
  LL ch = getcx();
  LL sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      sign = -1;
    ch = getcx();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getcx();
  n = n * sign;
}

int main() {

  LL n;
  cin >> n;

  LL c = n;
  vector<pair<int, int>> v;
  for (LL i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (c % i == 0) {
      cnt++;
      c /= i;
    }
    v.PB(MP(i, cnt));
  }

  if (c > 1)
    v.PB(MP(c, 1));

  LL ans = 0;
  for (int i = 0; i < v.size(); i++) {
    int val = v[i].Y;
    int s = 1;
    while (val > 0) {
      if (val - s > s) {
        ans++;
        val -= s;
      } else {
        ans++;
        val = 0;
      }
      s++;
    }
  }
  cout << ans << endl;

  return 0;
}