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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const long double PI = 3.1415926535897932;
const long long MAXLL = 9223372036854775807;
const long long INF = 2305843009213693951;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};

#define lint boost::multiprecision::cpp_int;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long, long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long, vector<long long>, greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

#define unless(a) if (!(a))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rbf(a, x) for (auto &a : x)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
#define bitrep(i, s, n) for (int i = (s); i < (1LL << (n)); i++)
#define bitcheck(bit, i) (bit) & (1LL << (i))
#define Maxe(x) *max_element((x).begin(), (x).end())
#define Mine(x) *min_element((x).begin(), (x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin, (s))

void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; }
void YES(bool a) { cout << (a ? "YES" : "NO") << endl; }
template <class T, class U> auto max(T a, U b) { return a > b ? a : b; }
template <class T, class U> auto min(T a, U b) { return a < b ? a : b; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long cutup(long long a, long long b) { return (a + b - 1) / b; }
long long popcnt(long long a) { return __builtin_popcountll(a); }
template <class T, class U> inline bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> inline bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename t> constexpr t mpow(t a, long long b) {
  if (b == 0)
    return 1;
  if (a == 0)
    return 0;
  t x = 1;
  while (b > 0) {
    if (b & 1LL)
      x *= a;
    a *= a;
    b >>= 1LL;
  }
  return x;
}

template <typename t> constexpr t nCr(t n, int r) {
  if (r == 0)
    return 1;
  if (n == 0)
    return 0;
  if (n < r)
    return 0;
  t x = 1;
  for (int i = 1; i <= r; i++) {
    x *= n - i + 1;
    x /= i;
  }
  return x;
}

// 高速素因数分解
// 前処理O(nloglogn)
// クエリO(logn)
vector<bool> IsPrime;
vector<int> MinFactor;

vector<long long> preprocess(int n) {
  vector<long long> res;
  IsPrime.resize(n);
  MinFactor.resize(n);
  for (int i = 0; i < n; i++)
    IsPrime[i] = true, MinFactor[i] = -1;
  IsPrime[0] = false;
  IsPrime[1] = false;
  MinFactor[0] = 0;
  MinFactor[1] = 1;
  for (int i = 2; i < n; ++i) {
    if (IsPrime[i]) {
      MinFactor[i] = i;
      res.emplace_back(i);
      for (int j = i * 2; j < n; j += i) {
        IsPrime[j] = false;
        if (MinFactor[j] == -1)
          MinFactor[j] = i;
      }
    }
  }
  return res;
}

vector<pair<int, int>> fast_prime_factor(int n) {
  vector<pair<int, int>> res;
  while (n != 1) {
    int prime = MinFactor[n];
    int exp = 0;
    while (MinFactor[n] == prime) {
      ++exp;
      n /= prime;
    }
    res.emplace_back(make_pair(prime, exp));
  }
  return res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vl A(n);
  rep(i, n) cin >> A[i];
  preprocess((int)(1e6 + 5));
  map<ll, int> m;
  bool d = false;
  rep(i, n) {
    if (A[i] == 1) {
      d = true;
    }
    auto s = fast_prime_factor(A[i]);
    rbf(p, s) { m[p.first]++; }
  }
  bool c = false;
  rbf(p, m) {
    if (p.second == n && !d) {
      cout << "not coprime" << endl;
      return 0;
    }
    if (p.second > 1) {
      c = true;
    }
  }
  if (c)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const long double PI = 3.1415926535897932;
const long long MAXLL = 9223372036854775807;
const long long INF = 2305843009213693951;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};

#define lint boost::multiprecision::cpp_int;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long, long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long, vector<long long>, greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

#define unless(a) if (!(a))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rbf(a, x) for (auto &a : x)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
#define bitrep(i, s, n) for (int i = (s); i < (1LL << (n)); i++)
#define bitcheck(bit, i) (bit) & (1LL << (i))
#define Maxe(x) *max_element((x).begin(), (x).end())
#define Mine(x) *min_element((x).begin(), (x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin, (s))

void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; }
void YES(bool a) { cout << (a ? "YES" : "NO") << endl; }
template <class T, class U> auto max(T a, U b) { return a > b ? a : b; }
template <class T, class U> auto min(T a, U b) { return a < b ? a : b; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long cutup(long long a, long long b) { return (a + b - 1) / b; }
long long popcnt(long long a) { return __builtin_popcountll(a); }
template <class T, class U> inline bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> inline bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename t> constexpr t mpow(t a, long long b) {
  if (b == 0)
    return 1;
  if (a == 0)
    return 0;
  t x = 1;
  while (b > 0) {
    if (b & 1LL)
      x *= a;
    a *= a;
    b >>= 1LL;
  }
  return x;
}

template <typename t> constexpr t nCr(t n, int r) {
  if (r == 0)
    return 1;
  if (n == 0)
    return 0;
  if (n < r)
    return 0;
  t x = 1;
  for (int i = 1; i <= r; i++) {
    x *= n - i + 1;
    x /= i;
  }
  return x;
}

// 高速素因数分解
// 前処理O(nloglogn)
// クエリO(logn)
vector<bool> IsPrime;
vector<int> MinFactor;

vector<long long> preprocess(int n) {
  vector<long long> res;
  IsPrime.resize(n);
  MinFactor.resize(n);
  for (int i = 0; i < n; i++)
    IsPrime[i] = true, MinFactor[i] = -1;
  IsPrime[0] = false;
  IsPrime[1] = false;
  MinFactor[0] = 0;
  MinFactor[1] = 1;
  for (int i = 2; i < n; ++i) {
    if (IsPrime[i]) {
      MinFactor[i] = i;
      res.emplace_back(i);
      for (int j = i * 2; j < n; j += i) {
        IsPrime[j] = false;
        if (MinFactor[j] == -1)
          MinFactor[j] = i;
      }
    }
  }
  return res;
}

vector<pair<int, int>> fast_prime_factor(int n) {
  vector<pair<int, int>> res;
  while (n != 1) {
    int prime = MinFactor[n];
    int exp = 0;
    while (MinFactor[n] == prime) {
      ++exp;
      n /= prime;
    }
    res.emplace_back(make_pair(prime, exp));
  }
  return res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vl A(n);
  rep(i, n) cin >> A[i];
  preprocess((int)(1e6));
  map<ll, int> m;
  bool d = false;
  rep(i, n) {
    if (A[i] == 1) {
      d = true;
    }
    auto s = fast_prime_factor(A[i]);
    rbf(p, s) { m[p.first]++; }
  }
  bool c = false;
  rbf(p, m) {
    if (p.second == n && !d) {
      cout << "not coprime" << endl;
      return 0;
    }
    if (p.second > 1) {
      c = true;
    }
  }
  if (c)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
}