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

/*
    @uthor: Amit Kumar
    user --> GitHub: drviruses ; CodeChef: dr_virus_ ;
   Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define int long long
#define ld long double
#define ull unsigned long long
#define endl "\\n"

vector<int> arr;
void factorize(long long n) {
  int count = 0;

  // count the number of times 2 divides
  while (!(n % 2)) {
    n >>= 1; // equivalent to n=n/2;
    count++;
  }

  // if 2 divides it
  if (count)
    arr.push_back(count);

  // check for all the possible numbers that can
  // divide it
  for (long long i = 3; i <= sqrt(n); i += 2) {
    count = 0;
    while (n % i == 0) {
      count++;
      n = n / i;
    }
    if (count)
      arr.push_back(count);
  }

  // if n at the end is a prime number.
  if (n > 2)
    arr.push_back(1);
}

void virus() {
  int n;
  cin >> n;
  factorize(n);
  int pre[100000];
  pre[0] = 1;
  for (auto i = 1; i < 100000; i++) {
    pre[i] = pre[i - 1] + (i + 1);
  }
  int cnt = 0;
  for (auto i : arr) {
    // cout<<i<<endl;
    cnt += (upper_bound(pre, pre + 100000, i) - pre);
  }
  cout << cnt;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

  int t = 1;
  // cin>>t;
  while (t--) {
    auto start = high_resolution_clock::now();
    virus();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    // cout << "Time: "<<duration.count()<<endl;
    // your code goes here
  }
  return 0;
}

Error: WA

Fixed submission:

/*
    @uthor: Amit Kumar
    user --> GitHub: drviruses ; CodeChef: dr_virus_ ;
   Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define int long long
#define ld long double
#define ull unsigned long long
#define endl "\\n"

vector<int> arr;
void sieveOfEratosthenes(int N, int s[]) {

  vector<bool> prime(N + 1, false);

  for (int i = 2; i <= N; i += 2)
    s[i] = 2;

  // For odd numbers less then equal to n
  for (int i = 3; i <= N; i += 2) {
    if (prime[i] == false) {
      // s(i) for a prime is the number itself
      s[i] = i;

      // For all multiples of current prime number
      for (int j = i; j * i <= N; j += 2) {
        if (prime[i * j] == false) {
          prime[i * j] = true;

          // i is the smallest prime factor for
          // number "i*j".
          s[i * j] = i;
        }
      }
    }
  }
}

void generatePrimeFactors(int N) {

  int s[N + 1];

  // Filling values in s[] using sieve
  sieveOfEratosthenes(N, s);

  int curr = s[N]; // Current prime factor of N
  int cnt = 1;     // Power of current prime factor

  // Printing prime factors and their powers
  while (N > 1) {
    N /= s[N];

    if (curr == s[N]) {
      cnt++;
      continue;
    }

    arr.push_back(cnt);
    curr = s[N];
    cnt = 1;
  }
}

void virus() {
  int n;
  cin >> n;
  generatePrimeFactors(n);
  int cnt = 0;
  for (auto i : arr) {
    if (i > 2)
      cnt += (i - 2) + 1;
    else
      cnt += i;
  }
  cout << cnt;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

  int t = 1;
  // cin>>t;
  while (t--) {
    auto start = high_resolution_clock::now();
    virus();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    // cout << "Time: "<<duration.count()<<endl;
    // your code goes here
  }
  return 0;
}