Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init()                                                                 \
  std::ios::sync_with_stdio(false);                                            \
  std::cin.tie(0);                                                             \
  std::cout << fixed << setprecision(15);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

// 約数列挙：nの約数を昇順に返す。
vector<long long> enumDivisors(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (n / i != i)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  Init();
  ll n;
  cin >> n;
  ll allGcd = -1;
  vi a(n);
  rep(i, n) {
    cin >> a[i];
    if (i == 0)
      allGcd = a[i];
    else
      allGcd = __gcd(allGcd, a[i]);
  }

  vector<bool> used(1000001, false);
  bool pc = true;
  rep(i, n) {
    auto eDiv = enumDivisors(a[i]);
    for (auto &num : eDiv) {
      if (num <= 1)
        continue;
      if (used[num]) {
        pc = false;
        break;
      } else {
        used[num] = true;
      }
      if (!pc)
        break;
    }
  }

  if (pc)
    cout << "pairwise coprime" << endl;
  else if (!pc && allGcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init()                                                                 \
  std::ios::sync_with_stdio(false);                                            \
  std::cin.tie(0);                                                             \
  std::cout << fixed << setprecision(15);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

// 約数列挙：nの約数を昇順に返す。
vector<long long> enumDivisors(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (n / i != i)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  Init();
  ll n;
  cin >> n;
  ll allGcd = -1;
  vi a(n);
  rep(i, n) {
    cin >> a[i];
    if (i == 0)
      allGcd = a[i];
    else
      allGcd = __gcd(allGcd, a[i]);
  }

  vector<bool> used(1000001, false);
  bool pc = true;
  rep(i, n) {
    auto eDiv = enumDivisors(a[i]);
    for (auto &num : eDiv) {
      if (num <= 1)
        continue;
      if (used[num]) {
        pc = false;
        break;
      } else {
        used[num] = true;
      }
      if (!pc)
        break;
    }
    if (!pc)
      break;
  }

  if (pc)
    cout << "pairwise coprime" << endl;
  else if (!pc && allGcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}