Problem p02660 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x))
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

const in N = 1000000 /*値*/;
void eratosthenes(bool prime[N]) {
  rep(i, N) prime[i] = 1;
  prime[0] = prime[1] = 0;
  rep(i, N) {
    if (prime[i]) {
      for (int j = i + i; j < N; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  in n;
  cin >> n;
  bool prime[N];
  vector<pair<in, int>> p;
  eratosthenes(prime);
  rep(i, N) {
    if (prime[i]) {
      pair<in, int> a;
      a.first = i;
      a.second = 0;
      p.push_back(a);
    }
  }
  int adi = 0;
  int m = p.size();
  // int M=1;
  /*rep(i,m){
    if(p.at(i).first*p.at(i).first>n) break;
    M=i;
  }*/

  while (n > 1) {
    rep(i, m + 1) {

      if (n % p.at(i).first == 0 && i != m) {
        // cout<<p.at(i).first;

        p.at(i).second++;
        if (p.at(i).first != 0)
          n = n / p.at(i).first;
        break;
      }
      if (i == m) {
        adi = 1;
        n = 1;
        break;
      }
    }
  }

  int ans = adi;
  // cout<<ans<<endl;

  rep(i, m) {
    int b = p.at(i).second;
    if (b == 0)
      continue;
    if (b < 3) {
      ans += 1;
      continue;
    }
    if (b < 6) {
      ans += 2;
      continue;
    }
    if (b < 10) {
      ans += 3;
      continue;
    }
    if (b < 15) {
      ans += 4;
      continue;
    }
    if (b < 21) {
      ans += 5;
      continue;
    }
    if (b < 28) {
      ans += 6;
      continue;
    }
    if (b < 36) {
      ans += 7;
      continue;
    }
    ans += 8;
  }

  cout << ans << endl;
  /*rep(i,50)
    cout<<p.at(i).first<<" ";*/
  // cout<<m<
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x))
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

const in N = 1000000 /*値*/;
void eratosthenes(bool prime[N]) {
  rep(i, N) prime[i] = 1;
  prime[0] = prime[1] = 0;
  rep(i, N) {
    if (prime[i]) {
      for (int j = i + i; j < N; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  in n;
  cin >> n;
  bool prime[N];
  vector<pair<in, int>> p;
  eratosthenes(prime);
  rep(i, N) {
    if (prime[i]) {
      pair<in, int> a;
      a.first = i;
      a.second = 0;
      p.push_back(a);
    }
  }
  int adi = 0;
  int m = p.size();
  // int M=1;
  /*rep(i,m){
    if(p.at(i).first*p.at(i).first>n) break;
    M=i;
  }*/

  while (n > 1) {
    rep(i, m + 1) {

      if (i != m && n % p.at(i).first == 0) {
        // cout<<p.at(i).first;

        p.at(i).second++;
        if (p.at(i).first != 0)
          n = n / p.at(i).first;
        break;
      }
      if (i == m) {
        adi = 1;
        n = 1;
        break;
      }
    }
  }

  int ans = adi;
  // cout<<ans<<endl;

  rep(i, m) {
    int b = p.at(i).second;
    if (b == 0)
      continue;
    if (b < 3) {
      ans += 1;
      continue;
    }
    if (b < 6) {
      ans += 2;
      continue;
    }
    if (b < 10) {
      ans += 3;
      continue;
    }
    if (b < 15) {
      ans += 4;
      continue;
    }
    if (b < 21) {
      ans += 5;
      continue;
    }
    if (b < 28) {
      ans += 6;
      continue;
    }
    if (b < 36) {
      ans += 7;
      continue;
    }
    ans += 8;
  }

  cout << ans << endl;
  /*rep(i,50)
    cout<<p.at(i).first<<" ";*/
  // cout<<m<
}