Problem p02574 (C++)

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

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
        while(x!=parent[x]){
                parent[x] = parent[parent[x]];
                x = parent[x];
        }
        return x;
}

void sunion(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx != ry){
                if(Size[rx] > Size[ry]){
                        parent[ry] = parent[rx];
                        Size[rx] += Size[ry];
                }
                else{
                        parent[rx] = parent[ry];
                        Size[ry] += Size[rx];
                }
        }
}
*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  // cin >> tc;
  const int N = 1000;
  int lp[N + 1];
  vector<int> pr;

  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
  while (tc--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    map<int, int> c;
    for (auto x : a) {
      int t = x;
      for (int j = 0; pr[j] * pr[j] <= t; j++) {
        if (t % pr[j] == 0)
          c[pr[j]]++;
        while (t % pr[j] == 0)
          t /= pr[j];
      }
      if (t != 1)
        c[t]++;
    }
    bool ok = true;
    for (auto x : c) {
      if (x.second >= 2) {
        ok = false;
        break;
      }
    }

    if (ok)
      cout << "pairwise coprime\n";
    else {
      int g = a[0];
      for (int i = 0; i < n; i++)
        g = __gcd(g, a[i]);
      if (g == 1)
        cout << "setwise coprime\n";
      else
        cout << "not coprime\n";
    }
  }
  return 0;
}


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

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
        while(x!=parent[x]){
                parent[x] = parent[parent[x]];
                x = parent[x];
        }
        return x;
}

void sunion(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx != ry){
                if(Size[rx] > Size[ry]){
                        parent[ry] = parent[rx];
                        Size[rx] += Size[ry];
                }
                else{
                        parent[rx] = parent[ry];
                        Size[ry] += Size[rx];
                }
        }
}
*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  // cin >> tc;
  const int N = 1000;
  int lp[N + 1];
  vector<int> pr;

  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
  while (tc--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    map<int, int> c;
    for (auto x : a) {
      int t = x;
      for (int j = 0; j < (int)pr.size() && pr[j] * pr[j] <= t; j++) {
        if (t % pr[j] == 0)
          c[pr[j]]++;
        while (t % pr[j] == 0)
          t /= pr[j];
      }
      if (t != 1)
        c[t]++;
    }
    bool ok = true;
    for (auto x : c) {
      if (x.second >= 2) {
        ok = false;
        break;
      }
    }

    if (ok)
      cout << "pairwise coprime\n";
    else {
      int g = a[0];
      for (int i = 0; i < n; i++)
        g = __gcd(g, a[i]);
      if (g == 1)
        cout << "setwise coprime\n";
      else
        cout << "not coprime\n";
    }
  }
  return 0;
}