Problem p02660 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fr(i, n) for (i = 0; i < n; i++)
#define frs(i, a, n) for (i = a; i < n; i++)
#define frv(i, n) for (i = n - 1; i >= 0; i--)

#define ne cout << "\\n";
#define cas(i) cout << "Case #" << i << ": "

#define vpi vector<pair<int, int>>
#define vpin(v, a, b) v.push_back(make_pair(a, b))
#define vsort(v) sort(v.begin(), v.end());
#define siz 1000005
bool prm[siz + 5];
ll lis[siz + 5];
ll pr = 0;
void sieve() {
  ll i, n, j;
  pr = 0;
  memset(prm, true, sizeof(prm));

  for (i = 2; i * i <= siz; i++) {
    if (prm[i]) {
      for (j = i * i; j < siz; j += i)
        prm[j] = false;
    }
  }
  for (i = 2; i < siz; i++) {
    if (prm[i]) {
      lis[pr++] = i;
    }
  }
}
ll lisi[100];
void gen() {
  ll i, n, x = 0, r = 0;
  for (i = 0; x <= 40; i++) {
    x += (++r);
    lisi[i] = x;
    //        cout<<i<<" "<<lisi[i]<<"\\n";
  }
}
int dis(int a, int b) {
  if (a - b < 0)
    return b - a;
  return a - b;
}
ll sol(ll n) {
  ll j, i, pp, x, cnt = 0, an = 0;
  pp = 0;
  for (i = lis[pp]; i * i <= n;) {
    if (n % i == 0) {
      cnt = 0;
      while (n % i == 0 && n > 1) {
        n /= i;
        cnt++;
      }
      for (j = 0; j < 9; j++) {
        if (cnt == lisi[j]) {
          an += (j + 1);
          break;
        } else if (cnt < lisi[j]) {
          an += j;
          break;
        }
      }
    }
    i = lis[pp++];
    if (pp >= pr)
      break;
  }
  if (n > 1)
    an++;
  return an;
}
int main() {
  sieve();
  gen();
  ll n;
  cin >> n;
  cout << sol(n) << "\\n";

  return 0;
}


Error: 0

Fixed submission:


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fr(i, n) for (i = 0; i < n; i++)
#define frs(i, a, n) for (i = a; i < n; i++)
#define frv(i, n) for (i = n - 1; i >= 0; i--)

#define ne cout << "\\n";
#define cas(i) cout << "Case #" << i << ": "

#define vpi vector<pair<int, int>>
#define vpin(v, a, b) v.push_back(make_pair(a, b))
#define vsort(v) sort(v.begin(), v.end());
#define siz 1000000
bool prm[siz + 5];
ll lis[siz + 5];
ll pr = 0;
void sieve() {
  ll i, n, j;
  pr = 0;
  memset(prm, true, sizeof(prm));

  for (i = 2; i * i <= siz; i++) {
    if (prm[i]) {
      for (j = i * i; j <= siz; j += i)
        prm[j] = false;
    }
  }
  for (i = 2; i < siz; i++) {
    if (prm[i]) {
      lis[pr++] = i;
    }
  }
}
ll lisi[100];
void gen() {
  ll i, n, x = 1, r = 1;
  for (i = 0; x <= 40; i++) {
    lisi[i] = x;
    x += (++r);
  }
}
int dis(int a, int b) {
  if (a - b < 0)
    return b - a;
  return a - b;
}
ll sol(ll n) {
  ll j, i, pp, x, cnt = 0, an = 0;
  pp = 0;
  for (i = lis[pp]; i * i <= n && n > 1;) {
    if (n % i == 0) {
      cnt = 0;
      while (n % i == 0 && n > 0) {
        n /= i;
        cnt++;
      }
      for (j = 0; j < 8; j++) {
        if (cnt == lisi[j]) {
          an += (j + 1);
          break;
        } else if (cnt < lisi[j]) {
          an += j;
          break;
        }
      }
    }
    i = lis[pp++];
  }
  if (n > 1)
    an++;
  return an;
}
int main() {
  sieve();
  gen();
  ll n;
  cin >> n;
  cout << sol(n) << "\\n";
  int T, tt, N, i, j;

  return 0;
}