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

#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
const ll mod = 1000000007;
struct UnionFind {
  vector<int> par; // par[i]:iの親の番号

  UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
    for (int i = 0; i < N; ++i)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]); // 経路圧縮
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
  }

  bool same(int x, int y) { // 2つのデータx,yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
vector<int> cnt;
bool divisor(ll n) {
  bool ok = true;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt[i]++;
      if (i * i != n)
        cnt[n / i]++;
      if (i != 1 && 1 < cnt[i])
        ok = false;
      if (n / i != 1 && 1 < cnt[n / i])
        ok = false;
    }
  }
  return ok;
}
ll getGCD(ll a, ll b) {
  // Greatest Common Divisor
  if (b == 0)
    return a;
  return getGCD(b, a % b);
}
int main() {
  /*int d, t, s; cin >> d >> t >> s;
  if (d <= t * s) cout << "Yes" << endl;
  else cout << "No" << endl;
  */

  /*string s, t; cin >> s >> t;
  int mx = 0;
  rep(i, s.size()) {
      int tmp = 0;
      if (s.size() < i + t.size()) continue;
      rep(j, t.size()) {
          if (s[i + j] == t[j]) tmp++;
      }
      mx = max(mx, tmp);
  }
  cout << t.size() - mx << endl;
  */

  /*int n; cin >> n;
  vector<ll> a(n);
  vector<ll> sum(n + 1, 0);
  sum[0] = 0;
  rep(i, n) {
      cin >> a[i];
      sum[i + 1] = a[i] + sum[i];
      sum[i + 1] %= mod;
  }
  ll ans = 0;
  rep(i, n) {
      ll s = sum.back() - sum[i + 1];
      s %= mod;
      if (s < 0) s += mod;
      ans += a[i] * s;
      ans %= mod;
  }
  cout << ans << endl;
  */

  /*int n, m; cin >> n >> m;
  UnionFind tree(n);
  rep(i, m) {
      int x, y; cin >> x >> y;
      tree.unite(x - 1, y - 1);
  }
  int ans = 0;
  vector<int> cnt(n, 0);
  rep(i, n) {
      cnt[tree.root(i)]++;
  }
  rep(i, n) {
      ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
  */

  int n;
  cin >> n;
  vector<ll> a(n);
  bool pc = true;
  cnt.assign(1000005, 0);
  rep(i, n) {
    cin >> a[i];
    if (pc)
      pc = divisor(a[i]);
  }
  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll gcd = a[0];
  for (int i = 1; i < n; ++i) {
    gcd = getGCD(gcd, a[i]);
  }
  if (gcd == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
const ll mod = 1000000007;
struct UnionFind {
  vector<int> par; // par[i]:iの親の番号

  UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
    for (int i = 0; i < N; ++i)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]); // 経路圧縮
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
  }

  bool same(int x, int y) { // 2つのデータx,yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
vector<int> cnt;
bool divisor(ll n) {
  bool ok = true;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      cnt[i]++;
      if (i * i != n)
        cnt[n / i]++;
      if (i != 1 && 1 < cnt[i])
        ok = false;
      if (1 < cnt[n / i])
        ok = false;
    }
  }
  return ok;
}
ll getGCD(ll a, ll b) {
  // Greatest Common Divisor
  if (b == 0)
    return a;
  return getGCD(b, a % b);
}
int main() {
  /*int d, t, s; cin >> d >> t >> s;
  if (d <= t * s) cout << "Yes" << endl;
  else cout << "No" << endl;
  */

  /*string s, t; cin >> s >> t;
  int mx = 0;
  rep(i, s.size()) {
      int tmp = 0;
      if (s.size() < i + t.size()) continue;
      rep(j, t.size()) {
          if (s[i + j] == t[j]) tmp++;
      }
      mx = max(mx, tmp);
  }
  cout << t.size() - mx << endl;
  */

  /*int n; cin >> n;
  vector<ll> a(n);
  vector<ll> sum(n + 1, 0);
  sum[0] = 0;
  rep(i, n) {
      cin >> a[i];
      sum[i + 1] = a[i] + sum[i];
      sum[i + 1] %= mod;
  }
  ll ans = 0;
  rep(i, n) {
      ll s = sum.back() - sum[i + 1];
      s %= mod;
      if (s < 0) s += mod;
      ans += a[i] * s;
      ans %= mod;
  }
  cout << ans << endl;
  */

  /*int n, m; cin >> n >> m;
  UnionFind tree(n);
  rep(i, m) {
      int x, y; cin >> x >> y;
      tree.unite(x - 1, y - 1);
  }
  int ans = 0;
  vector<int> cnt(n, 0);
  rep(i, n) {
      cnt[tree.root(i)]++;
  }
  rep(i, n) {
      ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
  */

  int n;
  cin >> n;
  vector<ll> a(n);
  bool pc = true;
  cnt.assign(100005, 0);
  rep(i, n) {
    cin >> a[i];
    if (pc)
      pc = divisor(a[i]);
  }
  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll gcd = a[0];
  for (int i = 1; i < n; ++i) {
    gcd = getGCD(gcd, a[i]);
  }
  if (gcd == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;

  return 0;
}