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

#include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int
#define pb push_back
#define fe first
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int, int>, pair<int, int>>
#define se second
#define endl "\\n"
#define pi pair<int, int>
#define mi map<int, int>
#define mii map<pi, int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846

const int N = 1e3 + 5;

int mod = 1e9 + 7;
int dx[4] = {0, 0, +1, -1};
int dy[4] = {+1, -1, 0, 0};

int po(int a, int b) {
  a %= mod;
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

int n;
vi pr;

void cal(int n) {
  vi a(n + 1, 1);
  rep(i, 2, n) {
    if (!a[i])
      continue;
    pr.pb(i);
    for (int j = 2 * i; j <= n; j += i)
      a[j] = 0;
  }
}

int can(vi a) {
  cal(N);
  set<int> st;
  for (int x : a) {
    for (int p : pr) {
      if (x % p == 0) {
        if (st.count(p))
          return 0;
        st.insert(p);
        while (x % p == 0)
          x /= p;
      }
    }

    if (x > 1) {
      if (st.count(x))
        return 0;
      st.insert(x);
    }
  }

  return 1;
}

void solve() {
  cin >> n;
  vi a(n, 0);
  rep(i, 0, n) { cin >> a[i]; }
  if (can(a)) {
    cout << "pairwise coprime\\n";
    return;
  }
  int d = a[0];
  rep(i, 0, n) d = __gcd(d, a[i]);
  if (d == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}

int32_t main() {
  cool;
  int t = 1;

  //~ cin>>t;
  while (t--)
    solve();

  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int, int>, pair<int, int>>
#define se second
#define endl "\\n"
#define pi pair<int, int>
#define mi map<int, int>
#define mii map<pi, int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846

const int N = 1e3 + 5;

int mod = 1e9 + 7;
int dx[4] = {0, 0, +1, -1};
int dy[4] = {+1, -1, 0, 0};

int po(int a, int b) {
  a %= mod;
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

int n, spf[N], vis[N];
mi mp;

void cal_spf() {
  spf[1] = 1;
  for (int i = 2; i < N; i++)
    spf[i] = i;
  for (int i = 4; i < N; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < N; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}

void get_fn(int x) {

  memset(vis, -1, sizeof(vis));
  while (x != 1) {
    if (vis[spf[x]] == -1) {
      vis[spf[x]] = 1;
      mp[spf[x]]++;
    }
    x /= spf[x];
  }
}

void solve() {
  cin >> n;
  vi a(n, 0);
  rep(i, 0, n) { cin >> a[i]; }
  //~ sort(all(a));
  int g = 0;
  rep(i, 0, n) { g = __gcd(g, a[i]); }

  if (g > 1) {
    cout << "not coprime\\n";
    return;
  }

  rep(i, 0, n) { get_fn(a[i]); }

  int f = 0;
  for (auto to : mp) {
    if (to.se > 1) {
      f = 1;
      break;
    }
  }
  if (!f) {
    cout << "pairwise coprime\\n";
    return;
  }

  if (g == 1) {
    cout << "setwise coprime\\n";
    return;
  }

  cout << "not coprime\\n";
}

int32_t main() {
  cool;
  int t = 1;

  cal_spf();
  // cin>>t;
  while (t--)
    solve();

  return 0;
}