Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                                                                \
  cerr << #v ":[ ";                                                            \
  for (auto macro_vi : v) {                                                    \
    cerr << macro_vi << " ";                                                   \
  }                                                                            \
  cerr << "]" << endl;
#define ddump(v)                                                               \
  cerr << #v ":" << endl;                                                      \
  for (auto macro_row : v) {                                                   \
    cerr << "[";                                                               \
    for (auto macro__vi : macro_row) {                                         \
      cerr << macro__vi << " ";                                                \
    }                                                                          \
    cerr << "]" << endl;                                                       \
  }
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;

int main() {
  lint N;
  cin >> N;
  vector<lint> A(N);
  rep(i, N) cin >> A[i];

  const lint M = 20;
  vector<vector<lint>> primes(M + 1, vector<lint>(0));
  for (int p = 2; p <= M; p++) {
    if (primes[p].size() != 0)
      continue;
    for (int pk = p; pk <= M; pk += p) {
      primes[pk].push_back(p);
    }
  }

  lint G = 0;
  rep(i, N) G = __gcd(G, A[i]);
  if (G != 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  set<lint> used;
  for (int i = 0; i < N; i++) {
    for (auto p : primes[A[i]]) {
      if (used.count(p) == 1) {
        cout << "setwise coprime" << endl;
        return 0;
      } else {
        used.insert(p);
      }
    }
  }

  cout << "pairwise coprime" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                                                                \
  cerr << #v ":[ ";                                                            \
  for (auto macro_vi : v) {                                                    \
    cerr << macro_vi << " ";                                                   \
  }                                                                            \
  cerr << "]" << endl;
#define ddump(v)                                                               \
  cerr << #v ":" << endl;                                                      \
  for (auto macro_row : v) {                                                   \
    cerr << "[";                                                               \
    for (auto macro__vi : macro_row) {                                         \
      cerr << macro__vi << " ";                                                \
    }                                                                          \
    cerr << "]" << endl;                                                       \
  }
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;

int main() {
  lint N;
  cin >> N;
  vector<lint> A(N);
  rep(i, N) cin >> A[i];

  const lint M = 1001000;
  vector<vector<lint>> primes(M + 1, vector<lint>(0));
  for (int p = 2; p <= M; p++) {
    if (primes[p].size() != 0)
      continue;
    for (int pk = p; pk <= M; pk += p) {
      primes[pk].push_back(p);
    }
  }

  lint G = 0;
  rep(i, N) G = __gcd(G, A[i]);
  if (G != 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  set<lint> used;
  for (int i = 0; i < N; i++) {
    for (auto p : primes[A[i]]) {
      if (used.count(p) == 1) {
        cout << "setwise coprime" << endl;
        return 0;
      } else {
        used.insert(p);
      }
    }
  }

  cout << "pairwise coprime" << endl;

  return 0;
}