Problem p02574 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1 * INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1 * LLINF;

template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
                                  Container const &x) {
  os << "{ ";
  for (auto &y : x)
    os << y << " ";
  return os << "}";
}

template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
  return os << "[ " << p.first << ", " << p.second << "]";
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;

#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define exists(x, m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

template <typename T>
tuple<vector<T>, vector<bool>, vector<T>> prime_sieve(T lim) {
  vector<T> primes = vector<T>();
  vector<T> lp = vector<T>();
  vector<bool> composite = vector<bool>(lim + 1);
  for (T num = 2; num <= lim; num++) {
    if (!composite[num])
      primes.pb(num);
    for (int i = 0; i < isize(primes) and num * primes[i] <= lim; i++) {
      composite[num * primes[i]] = true;
      if (num % primes[i] == 0) {
        lp[num] = primes[i];
        break;
      }
    }
  }
  return {primes, composite, lp};
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi A = vi();
  int maxx = 0;
  rep(i, n) {
    int x;
    cin >> x;
    A.pb(x);
    maxx = max(maxx, x);
  }
  auto [primes, composite, lp] =
      prime_sieve((int)min(1e3 + 100, ceil(sqrt(maxx)) + 100));
  umap<int, int> prime_freq = umap<int, int>();
  for (const int &a : A) {
    int b = a;
    for (int i = 0; primes[i] * primes[i] <= b; i++) {
      if (b % primes[i] == 0)
        prime_freq[primes[i]]++;
      while (b % primes[i] == 0)
        b /= primes[i];
    }
    if (b != 1)
      prime_freq[b]++;
  }
  int max_freq = 0;
  for (const auto &[p, freq] : prime_freq) {
    max_freq = max(max_freq, freq);
  }
  if (max_freq <= 1) {
    cout << "pairwise coprime";
  } else {
    cout << (max_freq < n ? "setwise coprime" : "not coprime");
  }
}

Fixed submission:
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1 * INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1 * LLINF;

template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
                                  Container const &x) {
  os << "{ ";
  for (auto &y : x)
    os << y << " ";
  return os << "}";
}

template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
  return os << "[ " << p.first << ", " << p.second << "]";
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;

#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define exists(x, m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

template <typename T>
tuple<vector<T>, vector<bool>, vector<T>> prime_sieve(T lim) {
  vector<T> primes = vector<T>();
  vector<T> lp = vector<T>(lim + 1, 0);
  vector<bool> composite = vector<bool>(lim + 1);
  for (T num = 2; num <= lim; num++) {
    if (!composite[num])
      primes.pb(num);
    for (int i = 0; i < isize(primes) and num * primes[i] <= lim; i++) {
      composite[num * primes[i]] = true;
      if (num % primes[i] == 0) {
        lp[num] = primes[i];
        break;
      }
    }
  }
  return {primes, composite, lp};
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi A = vi();
  int maxx = 0;
  rep(i, n) {
    int x;
    cin >> x;
    A.pb(x);
    maxx = max(maxx, x);
  }
  auto [primes, composite, lp] =
      prime_sieve((int)min(1e3 + 100, ceil(sqrt(maxx)) + 100));
  umap<int, int> prime_freq = umap<int, int>();
  for (const int &a : A) {
    int b = a;
    for (int i = 0; primes[i] * primes[i] <= b; i++) {
      if (b % primes[i] == 0)
        prime_freq[primes[i]]++;
      while (b % primes[i] == 0)
        b /= primes[i];
    }
    if (b != 1)
      prime_freq[b]++;
  }
  int max_freq = 0;
  for (const auto &[p, freq] : prime_freq) {
    max_freq = max(max_freq, freq);
  }
  if (max_freq <= 1) {
    cout << "pairwise coprime";
  } else {
    cout << (max_freq < n ? "setwise coprime" : "not coprime");
  }
}