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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;

template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

#define output cout

void debug_out() { output << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  output << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) output << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// functions: set.insert(val), *(set.find_by_order(order-1)),
// set.order_of_key(val)

#define ll long long
#define ull unsigned long long
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define vt vector
#define vll vt<ll>
#define pll pair<ll, ll>
#define vpll vt<pll>
#define vvll vt<vll>
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (ll i = 0; i < n; i++)
#define ffo(i, a, b) for (ll i = a; i <= b; i++)
#define rfo(i, a, b) for (ll i = a; i >= b; i--)
#define space cout << "\\n\\n";
#define endl "\\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll, vll, greater<ll>>
#define fps(x, y) fixed << setprecision(y) << x
#define merg(a, b, c)                                                          \\
  set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.begin()))
#define set_ar(arr, v) memset(arr, v, sizeof(arr))
#define go_t                                                                   \\
  int testcases;                                                               \\
  cin >> testcases;                                                            \\
  ffo(caseno, 1, testcases)

#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime                                                                  \\
  auto z1z = duration_cast<microseconds>(stop - start);                        \\
  cout << "Time elapsed : " << z1z.count() << " microseconds\\n"

const ll mod = 1e9 + 7;
const ll N = 1e6 + 6;
const ll maxN = 1e6 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// up, right, down, left

ll powerM(ll x, ll y, ll M = mod) { // default argument
  ll v = 1;
  x = x % M;
  while (y > 0) {
    if (y & 1)
      v = (v * x) % M;
    y = y >> 1;
    x = (x * x) % M;
  }
  return v;
}

ll power(ll x, ll y) {
  ll v = 1;
  while (y > 0) {
    if (y & 1)
      v = v * x;
    y = y >> 1;
    x = x * x;
  }
  return v;
}

ll n;
ll a[maxN];
int hash1[maxN];
int h1[maxN];

vt<int> spf(maxN);
void spfsieve() {

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("in6.txt", "r", stdin);
  freopen("out2.txt", "w", stdout);
#endif
  FIO spfsieve();
  // ll cnt = 0;
  // for (int i = 1; i <= 10; ++i) {
  // 	if (spf[i] == i)
  // 		++cnt;
  // }
  // cout << cnt; // 78498
  cin >> n;
  ll c = 0;
  ll flg = 0;
  ll g = 0;
  ll is_1 = 0;
  set<int> s[n];
  FOR(i, n) {
    cin >> a[i];
    g = __gcd(g, a[i]);
    ll t = a[i];
    while (t != 1) {
      s[i].insert(spf[t]);
      t = t / spf[t];
    }
    // s[i].insert(a[i]);
    hash1[a[i]]++;
    if (a[i] == 1)
      is_1 = 1;
    if (hash1[a[i]] > 1)
      flg = 1;
    else
      ++c;
  }
  // if (c == n) {
  // no number is repeating itself
  ll f1 = 0;
  for (int i = 0; i < n; ++i) {
    for (auto &it : s[i]) {
      if (h1[it] == 1) {
        f1 = 1;
        break;
      }
      h1[it] = 1;
    }
  }
  //
  if (f1 == 0)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  // }
  // else {
  // 	// some numbers which repeat themselves
  // 	if (g == 1 && is_1 == 1) {
  // 		cout << "pairwise coprime";
  // 	}
  // 	else if (g == 1) {
  // 		cout << "setwise coprime";
  // 	}
  // 	else {
  // 		cout << "not coprime";
  // 	}
  // }
  return 0;
}


Error: WA

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;

template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

#define output cout

void debug_out() { output << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  output << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) output << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// functions: set.insert(val), *(set.find_by_order(order-1)),
// set.order_of_key(val)

#define ll long long
#define ull unsigned long long
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define vt vector
#define vll vt<ll>
#define pll pair<ll, ll>
#define vpll vt<pll>
#define vvll vt<vll>
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (ll i = 0; i < n; i++)
#define ffo(i, a, b) for (ll i = a; i <= b; i++)
#define rfo(i, a, b) for (ll i = a; i >= b; i--)
#define space cout << "\\n\\n";
#define endl "\\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll, vll, greater<ll>>
#define fps(x, y) fixed << setprecision(y) << x
#define merg(a, b, c)                                                          \\
  set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.begin()))
#define set_ar(arr, v) memset(arr, v, sizeof(arr))
#define go_t                                                                   \\
  int testcases;                                                               \\
  cin >> testcases;                                                            \\
  ffo(caseno, 1, testcases)

#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime                                                                  \\
  auto z1z = duration_cast<microseconds>(stop - start);                        \\
  cout << "Time elapsed : " << z1z.count() << " microseconds\\n"

const ll mod = 1e9 + 7;
const ll N = 1e6 + 6;
const ll maxN = 1e6 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// up, right, down, left

ll powerM(ll x, ll y, ll M = mod) { // default argument
  ll v = 1;
  x = x % M;
  while (y > 0) {
    if (y & 1)
      v = (v * x) % M;
    y = y >> 1;
    x = (x * x) % M;
  }
  return v;
}

ll power(ll x, ll y) {
  ll v = 1;
  while (y > 0) {
    if (y & 1)
      v = v * x;
    y = y >> 1;
    x = x * x;
  }
  return v;
}

ll n;
ll a[maxN];
int hash1[maxN];
int h1[maxN];

vt<int> spf(maxN);
void spfsieve() {
  for (int i = 2; i < maxN; i += 2)
    spf[i] = 2;
  for (int i = 3; i < maxN; i += 2) {
    if (spf[i] == 0) {
      spf[i] = i;
      for (int j = 2 * i; j < maxN; j += i) {
        if (spf[j] == 0)
          spf[j] = i;
      }
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in6.txt", "r", stdin);
  freopen("out2.txt", "w", stdout);
#endif
  FIO spfsieve();
  // ll cnt = 0;
  // for (int i = 1; i <= 10; ++i) {
  // 	if (spf[i] == i)
  // 		++cnt;
  // }
  // cout << cnt; // 78498
  cin >> n;
  ll c = 0;
  ll flg = 0;
  ll g = 0;
  ll is_1 = 0;
  set<int> s[n];
  FOR(i, n) {
    cin >> a[i];
    g = __gcd(g, a[i]);
    ll t = a[i];
    while (spf[a[i]] != a[i]) {
      s[i].insert(spf[a[i]]);
      a[i] = a[i] / spf[a[i]];
    }
    s[i].insert(a[i]);
    hash1[a[i]]++;
    if (a[i] == 1)
      is_1 = 1;
    if (hash1[a[i]] > 1)
      flg = 1;
    else
      ++c;
  }
  if (c == n) {
    // no number is repeating itself
    ll f1 = 0;
    for (int i = 0; i < n; ++i) {
      for (auto &it : s[i]) {
        if (h1[it] == 1) {
          f1 = 1;
          break;
        }
        h1[it] = 1;
      }
    }
    //
    if (f1 == 0)
      cout << "pairwise coprime";
    else if (g == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  } else {
    // some numbers which repeat themselves
    if (g == 1) {
      cout << "setwise coprime";
    } else {
      cout << "not coprime";
    }
  }
  return 0;
}