Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b)                                                          \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT
#define chmax(x, a)                                                            \
  do {                                                                         \
    x = max(x, a);                                                             \
  } while (0)
#define chmin(x, a)                                                            \
  do {                                                                         \
    x = min(x, a);                                                             \
  } while (0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;

ll gcd(ll x, ll y) {
  if (y < x)
    swap(x, y);
  if (x == 0)
    return y;
  return gcd(y % x, x);
}

std::map<ll, ll> decomposePrime(ll n) {
  std::map<ll, ll> m;
  ll x = 2;
  while (x * x <= n) {
    if (n % x == 0) {
      m[x]++;
      n /= x;
    } else {
      x++;
    }
  }
  if (n > 1)
    m[n]++;
  return m;
}

void solve() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  bool pw = true;
  vector<bool> appeared(N);
  for (auto e : decomposePrime(a[0])) {
    appeared[e.first] = true;
  }
  for (ll i = 1; i < N; i++) {
    for (auto e : decomposePrime(a[i])) {
      if (appeared[e.first])
        pw = false;
      appeared[e.first] = true;
    }
  }
  if (pw) {
    cout << "pairwise coprime" << endl;
    return;
  }

  bool sw = true;
  ll t = a[0];
  for (ll i = 1; i < N; i++) {
    t = gcd(t, a[i]);
  }
  if (t != 1)
    sw = false;

  if (sw) {
    cout << "setwise  coprime" << endl;
    return;
  }

  cout << "not coprime" << endl;
}

int main() {
  // ll T;
  // cin >> T;
  // rep(_,T)
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b)                                                          \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT
#define chmax(x, a)                                                            \
  do {                                                                         \
    x = max(x, a);                                                             \
  } while (0)
#define chmin(x, a)                                                            \
  do {                                                                         \
    x = min(x, a);                                                             \
  } while (0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;

ll gcd(ll x, ll y) {
  if (y < x)
    swap(x, y);
  if (x == 0)
    return y;
  return gcd(y % x, x);
}

std::map<ll, ll> decomposePrime(ll n) {
  std::map<ll, ll> m;
  ll x = 2;
  while (x * x <= n) {
    if (n % x == 0) {
      m[x]++;
      n /= x;
    } else {
      x++;
    }
  }
  if (n > 1)
    m[n]++;
  return m;
}

void solve() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  bool pw = true;
  vector<bool> appeared(2000000);
  for (auto e : decomposePrime(a[0])) {
    appeared[e.first] = true;
  }
  for (ll i = 1; i < N; i++) {
    for (auto e : decomposePrime(a[i])) {
      if (appeared[e.first])
        pw = false;
      appeared[e.first] = true;
    }
  }
  if (pw) {
    cout << "pairwise coprime" << endl;
    return;
  }

  bool sw = true;
  ll t = a[0];
  for (ll i = 1; i < N; i++) {
    t = gcd(t, a[i]);
  }
  if (t != 1)
    sw = false;

  if (sw) {
    cout << "setwise  coprime" << endl;
    return;
  }

  cout << "not coprime" << endl;
}

int main() {
  // ll T;
  // cin >> T;
  // rep(_,T)
  solve();
  return 0;
}