Problem p02660 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin);
#define fout freopen("output", "w", stdout);
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x)                                                              \
  { cerr << #x << ": " << x << endl; }
#define whatis2(x, y)                                                          \
  {                                                                            \
    wt(x);                                                                     \
    wt(y);                                                                     \
    cerr << endl;                                                              \
  }
#define whatis3(x, y, z)                                                       \
  {                                                                            \
    wt(x);                                                                     \
    wt(y);                                                                     \
    wt(z);                                                                     \
    cerr << endl;                                                              \
  }
#define whatis4(x, y, z, a)                                                    \
  {                                                                            \
    wt(x);                                                                     \
    wt(y);                                                                     \
    wt(z);                                                                     \
    wt(a);                                                                     \
    cerr << endl;                                                              \
  }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

const int N = 100000;
int power[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n;
  ll cnt = 0;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      power[i] += 1;
    }
  }
  int ans = 0;
  if (n > 2) {
    /* power[n] += 1; */
    ans += 1;
  }
  for (int i = 0; i < N; ++i) {
    int val = 1;
    int cnt = 0;
    while (power[i]) {
      cnt += val;
      val += 1;
      /* if (i == 2) whatis(cnt); */
      if (cnt <= power[i]) {
        ans += 1;
      } else {
        break;
      }
    }
  }

  /* whatis(power[3]); */
  /* whatis(power[2]); */
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin);
#define fout freopen("output", "w", stdout);
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x)                                                              \
  { cerr << #x << ": " << x << endl; }
#define whatis2(x, y)                                                          \
  {                                                                            \
    wt(x);                                                                     \
    wt(y);                                                                     \
    cerr << endl;                                                              \
  }
#define whatis3(x, y, z)                                                       \
  {                                                                            \
    wt(x);                                                                     \
    wt(y);                                                                     \
    wt(z);                                                                     \
    cerr << endl;                                                              \
  }
#define whatis4(x, y, z, a)                                                    \
  {                                                                            \
    wt(x);                                                                     \
    wt(y);                                                                     \
    wt(z);                                                                     \
    wt(a);                                                                     \
    cerr << endl;                                                              \
  }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

const int N = 1000000;
int power[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n;
  ll cnt = 0;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      power[i] += 1;
    }
  }
  int ans = 0;
  if (n > 2) {
    /* power[n] += 1; */
    ans += 1;
  }
  for (int i = 0; i < N; ++i) {
    int val = 1;
    int cnt = 0;
    while (power[i]) {
      cnt += val;
      val += 1;
      /* if (i == 2) whatis(cnt); */
      if (cnt <= power[i]) {
        ans += 1;
      } else {
        break;
      }
    }
  }

  /* whatis(power[3]); */
  /* whatis(power[2]); */
  cout << ans << endl;

  return 0;
}