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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
// const int64 INF = 1LL << 58;
#define dame                                                                   \\
  {                                                                            \\
    puts("-1");                                                                \\
    return 0;                                                                  \\
  }
#define YES                                                                    \\
  {                                                                            \\
    cout << "YES" << endl;                                                     \\
    return 0;                                                                  \\
  }
#define NO                                                                     \\
  {                                                                            \\
    cout << "NO" << endl;                                                      \\
    return 0;                                                                  \\
  }
#define Yes                                                                    \\
  {                                                                            \\
    cout << "Yes" << endl;                                                     \\
    return 0;                                                                  \\
  }
#define No                                                                     \\
  {                                                                            \\
    cout << "No" << endl;                                                      \\
    return 0;                                                                  \\
  }
#define uniq(a)                                                                \\
  sort(all(a));                                                                \\
  (a).resize(unique(all(a)) - a.begin());
#define dab(v)                                                                 \\
  for (auto i : v)                                                             \\
    cout << i << ' ';                                                          \\
  cout << endl;
#define vin(v)                                                                 \\
  for (ll i = 0; i < v.size(); ++i)                                            \\
    cin >> v[i];
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

void dfs(int i, int j, int N, int M, vvi &garden) {
  if (garden.at(i).at(j) == 1)
    garden.at(i).at(j) = 0;
  repk(k, i - 1, i + 2) {
    repk(l, j - 1, j + 2) {
      if (k < 0 || k >= N || l < 0 || l >= M || (k == i && l == j))
        continue;
      cout << k << " " << l << endl;
      if (garden.at(k).at(l) == 1)
        dfs(k, l, N, M, garden);
    }
  }
}

int solve(int N, int M, vvi &garden) {
  int cnt = 0;
  rep(i, N) {
    rep(j, M) {
      if (garden.at(i).at(j) == 1) {
        cnt++;
        dfs(i, j, N, M, garden);
      }
    }
  }
  return cnt;
}
int get_n(int n) {
  for (int i = 0;; i++) {
    if (i * (i + 1) / 2 <= n && n < (i + 1) * (i + 2) / 2) {
      return i;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(18);

  long long int N;
  long long int M;
  cin >> N;
  if (N == 1) {
    cout << 0;
    return 0;
  }

  M = N;
  vi A(10e6, 0);

  // 素因数分解
  while (N != 1) {
    int flag = 0;
    repk(i, 2, sqrt(N) + 1) {
      // cout <<  N << " " << i << endl;
      if (N % i == 0) {
        flag = 1;
        N = N / i;
        A.at(i) += 1;
        // cout << i << " " << A.at(i) << " " << N << endl;
        break;
      }
    }
    if (flag == 0) {
      if (N < 10e6)
        A.at(N) += 1;
      else
        A.at(0) += 1;
      N = 1;
    }
  }

  int cnt = 0;
  rep(i, 10e6) { cnt += get_n(A.at(i)); }
  cout << cnt;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
// const int64 INF = 1LL << 58;
#define dame                                                                   \\
  {                                                                            \\
    puts("-1");                                                                \\
    return 0;                                                                  \\
  }
#define YES                                                                    \\
  {                                                                            \\
    cout << "YES" << endl;                                                     \\
    return 0;                                                                  \\
  }
#define NO                                                                     \\
  {                                                                            \\
    cout << "NO" << endl;                                                      \\
    return 0;                                                                  \\
  }
#define Yes                                                                    \\
  {                                                                            \\
    cout << "Yes" << endl;                                                     \\
    return 0;                                                                  \\
  }
#define No                                                                     \\
  {                                                                            \\
    cout << "No" << endl;                                                      \\
    return 0;                                                                  \\
  }
#define uniq(a)                                                                \\
  sort(all(a));                                                                \\
  (a).resize(unique(all(a)) - a.begin());
#define dab(v)                                                                 \\
  for (auto i : v)                                                             \\
    cout << i << ' ';                                                          \\
  cout << endl;
#define vin(v)                                                                 \\
  for (ll i = 0; i < v.size(); ++i)                                            \\
    cin >> v[i];
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

void dfs(int i, int j, int N, int M, vvi &garden) {
  if (garden.at(i).at(j) == 1)
    garden.at(i).at(j) = 0;
  repk(k, i - 1, i + 2) {
    repk(l, j - 1, j + 2) {
      if (k < 0 || k >= N || l < 0 || l >= M || (k == i && l == j))
        continue;
      cout << k << " " << l << endl;
      if (garden.at(k).at(l) == 1)
        dfs(k, l, N, M, garden);
    }
  }
}

int solve(int N, int M, vvi &garden) {
  int cnt = 0;
  rep(i, N) {
    rep(j, M) {
      if (garden.at(i).at(j) == 1) {
        cnt++;
        dfs(i, j, N, M, garden);
      }
    }
  }
  return cnt;
}
int get_n(int n) {
  for (int i = 0;; i++) {
    if (i * (i + 1) / 2 <= n && n < (i + 1) * (i + 2) / 2) {
      return i;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(18);

  long long int N;
  long long int M;
  cin >> N;
  if (N == 1) {
    cout << 0;
    return 0;
  }

  M = N;
  vi A(10e6, 0);
  int flag = 0;
  for (int i = 2; i < sqrt(N) + 1; i++) {
    if (N % i == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 0) {
    cout << 1;
    return 0;
  }
  while (N != 1) {
    repk(i, 2, N + 1) {
      if (N % i == 0) {
        N = N / i;
        A.at(i) += 1;
        // cout << i << " " << A.at(i) << " " << N << endl;
        break;
      }
    }
  }

  int cnt = 0;
  rep(i, 10e6) { cnt += get_n(A.at(i)); }
  cout << cnt;
  return 0;
}