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

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

class Prints {
private:
  class __Prints {
  public:
    __Prints(const char *sep, const char *term) : sep(sep), term(term) {}
    template <class... Args> void operator()(const Args &...args) const {
      print(args...);
    }

  private:
    const char *sep, *term;
    void print() const { std::cout << term; }
    void print_rest() const { std::cout << term; }
    template <class T, class... Tail>
    void print(const T &head, const Tail &...tail) const {
      std::cout << head, print_rest(tail...);
    }
    template <class T, class... Tail>
    void print_rest(const T &head, const Tail &...tail) const {
      std::cout << sep << head, print_rest(tail...);
    }
  };

public:
  Prints() {}
  __Prints operator()(const char *sep = " ", const char *term = "\\n") const {
    return __Prints(sep, term);
  }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

constexpr int MX_V = 1000000;
int cp[MX_V + 1];
int ns[MX_V + 1];

void solve() {
  for (ll i = 2; i <= MX_V; i++) {
    if (cp[i] == 0) {
      cp[i] = i;
    }
    for (ll j = i + i; j <= MX_V; j += i) {
      if (cp[j] != 0)
        continue;
      cp[j] = i;
    }
  }

  ll N;
  cin >> N;
  Vi A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  set<int> st;
  int mx = 0;
  for (ll i = 0; i < N; i++) {
    st.clear();
    int t = A[i];
    while (t > 1) {
      int q = cp[t];
      if (q > 1) {
        st.emplace(q);
        t /= q;
      }
    }
    for (auto x : st) {
      chmax(mx, ++ns[x]);
    }
  }

  if (mx <= 1) {
    prints()("pairwise coprime");
  } else if (mx < N) {
    prints()("setwise coprime");
  } else {
    prints()("not coprime");
  }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
  cin.tie(nullptr), cout.tie(nullptr);
  ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
  ifstream ifs("./in_out/input.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
  ofstream ofs("./in_out/output.txt");
  cout.rdbuf(ofs.rdbuf());
#endif
  cout << setprecision(18) << fixed;
  solve();
  cout << flush;
  return 0;
}


Error: -8

Fixed submission:

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

class Prints {
private:
  class __Prints {
  public:
    __Prints(const char *sep, const char *term) : sep(sep), term(term) {}
    template <class... Args> void operator()(const Args &...args) const {
      print(args...);
    }

  private:
    const char *sep, *term;
    void print() const { std::cout << term; }
    void print_rest() const { std::cout << term; }
    template <class T, class... Tail>
    void print(const T &head, const Tail &...tail) const {
      std::cout << head, print_rest(tail...);
    }
    template <class T, class... Tail>
    void print_rest(const T &head, const Tail &...tail) const {
      std::cout << sep << head, print_rest(tail...);
    }
  };

public:
  Prints() {}
  __Prints operator()(const char *sep = " ", const char *term = "\\n") const {
    return __Prints(sep, term);
  }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
  constexpr int MX_V = 1000000;
  int cp[MX_V + 1] = {};
  Vi ps;
  for (ll i = 2; i <= MX_V; i++) {
    if (cp[i] == -1) {
      ps.emplace_back(i);
      cp[i] = i;
    }
    for (ll j = i + i; j <= MX_V; j += i) {
      if (cp[j] != -1)
        continue;
      cp[j] = i;
    }
  }

  ll N;
  cin >> N;
  Vi A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  int ns[MX_V + 1] = {};

  set<int> st;
  int mx = 0;
  for (ll i = 0; i < N; i++) {
    st.clear();
    int t = A[i];
    while (t > 1) {
      int q = cp[t];
      if (q > 1) {
        st.emplace(q);
      }
      t /= q;
    }
    for (auto x : st) {
      chmax(mx, ++ns[x]);
    }
  }

  if (mx <= 1) {
    prints()("pairwise coprime");
  } else if (mx < N) {
    prints()("setwise coprime");
  } else {
    prints()("not coprime");
  }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
  cin.tie(nullptr), cout.tie(nullptr);
  ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
  ifstream ifs("./in_out/input.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
  ofstream ofs("./in_out/output.txt");
  cout.rdbuf(ofs.rdbuf());
#endif
  cout << setprecision(18) << fixed;
  solve();
  cout << flush;
  return 0;
}