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

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

typedef long long int ll;
#define cases                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define scan(n) scanf("%d", &n)
#define PI 3.1415926535897932384626433832795
#define int ll
#define loop0 for (int i = 0; i < n; i++)
#define loop1 for (int i = 1; i <= n; i++)
#define inpar0(ar)                                                             \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> ar[i];
#define inpar1(ar)                                                             \\
  for (int i = 1; i <= n; i++)                                                 \\
    cin >> ar[i];
#define showar0(ar)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << ar[i] << " ";
#define showar1(ar)                                                            \\
  for (int i = 1; i <= n; i++)                                                 \\
    cout << ar[i] << " ";
#define manu cout << (checkerCounter++) << endl;
int checkerCounter = 1;
int mod = 1000000007;
int maxn = 200001;
int binpow(int a, int b, int mod) {
  int res = 1;
  while (b > 0) {
    if (b % 2) {
      res = (res * a) % mod;
      b--;
    }
    a = (a * a) % mod;
    b /= 2;
  }
  return res % mod;
}
bool isPrime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

vector<int> vec;

void init() {
  vec.push_back(0);
  for (int i = 1; i < 20; i++) {
    int m1 = i * (i + 1);
    m1 /= 2;
    int m2 = (i + 1) * (i + 2);
    m2 /= 2;
    for (int j = m1; j < m2; j++) {
      vec.push_back(i);
      if (vec.size() > 100)
        break;
    }
    if (vec.size() > 100)
      break;
  }
}

signed main() {
  int n;
  cin >> n;
  init();
  int ans = 0;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      ans += vec[cnt];
      //            cout<<i<<" "<<cnt<<" "<<vec[cnt]<<" "<<ans<<endl;
    }
  }
  if (n != 1)
    ans++;
  cout << ans;
}


Error: WA

Fixed submission:

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

typedef long long int ll;
#define cases                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define scan(n) scanf("%d", &n)
#define PI 3.1415926535897932384626433832795
#define int ll
#define loop0 for (int i = 0; i < n; i++)
#define loop1 for (int i = 1; i <= n; i++)
#define inpar0(ar)                                                             \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> ar[i];
#define inpar1(ar)                                                             \\
  for (int i = 1; i <= n; i++)                                                 \\
    cin >> ar[i];
#define showar0(ar)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << ar[i] << " ";
#define showar1(ar)                                                            \\
  for (int i = 1; i <= n; i++)                                                 \\
    cout << ar[i] << " ";
#define manu cout << (checkerCounter++) << endl;
int checkerCounter = 1;
int mod = 1000000007;
int maxn = 200001;
int binpow(int a, int b, int mod) {
  int res = 1;
  while (b > 0) {
    if (b % 2) {
      res = (res * a) % mod;
      b--;
    }
    a = (a * a) % mod;
    b /= 2;
  }
  return res % mod;
}
bool isPrime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

vector<int> vec;

void init() {
  for (int i = 2; i <= 1000000; i++) {
    if (isPrime(i)) {
      for (int j = i; j <= 1000000; j *= i) {
        vec.push_back(j);
      }
    }
  }
  sort(vec.begin(), vec.end());
}

signed main() {
  init();
  int n;
  cin >> n;
  int cnt = 0;
  int num = 0;
  //    for(int i=0;i<10;i++)cout<<vec[i]<<" ";cout<<endl;
  while (n != 1 and n >= vec[num]) {
    //        cout<<n<<" "<<vec[num]<<endl;
    if (isPrime(n)) {
      cnt++;
      break;
    } else {
      if (n % vec[num] == 0) {
        n /= vec[num];
        cout << n << " " << vec[num] << endl;
        cnt++;
      }
      num++;
    }
  }
  cout << cnt;
}