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

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16); cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints
// xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
// find_by_order()  // order_of_key
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fi(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inff (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
#define flush fflush(stdout)
#define primeDEN 727999983
#define SPEED                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fp(i, a, n) for (ll i = n - 1; i > a; i--)
#define deb(x) cout << #x << " ---> " << x << endl;
#define X first
#define Y second
#define pia 3.1415926536
#define mod 1000000007
#define mod2 998244353

#define ml map<ll, ll>
#define mll map<pll, ll>
#define vvl vector<vl>
#define vvi vector<vi>
#define letsh(a, b) a << b
#define rigsh(a, b) a >> b
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}

ll power(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    n = n >> 1;
  }
  return ans;
}
ll power2(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = (ans * a);
    a = (a * a);
    n = n >> 1;
  }
  return ans;
}
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }

vll dir({{-1, 0}, {1, 0}, {0, 1}, {0, -1}});
bool inside(int x, int y) { return 1 <= min(x, y) && x <= 10000 && y <= 1000; }
void add(ll a, ll b) {}
ll sub(ll a, ll b) {
  a -= b;
  a %= mod;
  if (a < 0)
    (a += mod);
  return a;
}
#define N 1000500
#define block 300
vl vis(N, 1);

vector<int> prime;
void get_prime() {
  for (int i = 2; i <= N; i++) {
    if (vis[i])
      prime.push_back(i);
    for (int j = 0; j < prime.size() && i * prime[j] <= N; j++) {
      vis[i * prime[j]] = 0;
      if (!(i % prime[j]))
        break;
    }
  }
}
vl fre(N, 0);
void solve() {
  ll n;
  cin >> n;
  ll x = 0;
  vl a(n);
  ll f = 0;
  f(i, 0, n) {
    cin >> a[i];
    fre[a[i]]++;
    if (fre[a[i]] > 1 && a[i] != 1)
      f = 1;
    x = __gcd(x, a[i]);
  }
  if (x > 1) {
    cout << "not coprime" << endl;
    return;
  } else if (f) {
    cout << "setwise coprime" << endl;
    return;
  }
  ll tt = 0;
  sort(all(a));
  f(i, 0, prime.size()) {
    ll mx = a[n - 1], p = prime[i], t = p, sum = 0;
    while (t <= mx) {
      if (fre[t])
        sum += fre[t];
      if (sum >= 2)
        break;
      t += p;
    }
    if (sum >= 2) {
      tt = 1;
      break;
    }
  }
  if (!tt) {
    cout << "pairwise coprime" << endl;
  } else
    cout << "setwise coprime" << endl;
}

int main() {
  SPEED
  ll t = 1;
  get_prime();
  while (t--)
    solve();
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16); cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints
// xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
// find_by_order()  // order_of_key
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fi(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inff (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
#define flush fflush(stdout)
#define primeDEN 727999983
#define SPEED                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fp(i, a, n) for (ll i = n - 1; i > a; i--)
#define deb(x) cout << #x << " ---> " << x << endl;
#define X first
#define Y second
#define pia 3.1415926536
#define mod 1000000007
#define mod2 998244353

#define ml map<ll, ll>
#define mll map<pll, ll>
#define vvl vector<vl>
#define vvi vector<vi>
#define letsh(a, b) a << b
#define rigsh(a, b) a >> b
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}

ll power(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    n = n >> 1;
  }
  return ans;
}
ll power2(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = (ans * a);
    a = (a * a);
    n = n >> 1;
  }
  return ans;
}
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }

#define N 200050
#define block 300

vll dir({{-1, 0}, {1, 0}, {0, 1}, {0, -1}});
ll n, k;
vvl g(N);
vvl dp(N, vl(5, 0));
ll ans = 0;
vl si(N, 0);
bool inside(int x, int y) { return 1 <= min(x, y) && x <= N && y <= N; }
void add(ll a, ll b) {}
ll sub(ll a, ll b) {
  a -= b;
  a %= k;
  if (a < 0)
    (a += k);
  return a;
}
int lpf[N], mobius[N];

void least_prime_factor() {
  for (ll i = 2; i < N; i++)

    if (!lpf[i])

      for (ll j = i; j < N; j += i)
        if (!lpf[j])
          lpf[j] = i;
}

void Mobius() {
  for (ll i = 1; i < N; i++) {

    if (i == 1)
      mobius[i] = 1;
    else {

      if (lpf[i / lpf[i]] == lpf[i])
        mobius[i] = 0;

      else
        mobius[i] = -1 * mobius[i / lpf[i]];
    }
  }
}
ll gcd_pairs(vector<ll> a, int n) {
  ll maxi = 0;

  ll fre[N] = {0};

  for (ll i = 0; i < n; i++) {
    fre[a[i]]++;
    maxi = max(a[i], maxi);
  }

  least_prime_factor();
  Mobius();

  ll ans = 0;

  for (ll i = 1; i <= maxi; i++) {
    if (!mobius[i])
      continue;

    ll temp = 0;
    for (int j = i; j <= maxi; j += i)
      temp += fre[j];

    ans += temp * (temp - 1) / 2 * mobius[i];
  }

  return ans;
}
void solve() {
  ll n;
  cin >> n;
  ll x = 0;
  vl a(n);
  f(i, 0, n) {
    cin >> a[i];
    x = __gcd(x, a[i]);
  }
  if (x > 1) {
    cout << "not coprime" << endl;
    return;
  }
  sort(all(a));
  set<ll> s;
  f(i, 0, n) { s.insert(a[i]); }
  if (s.size() != n) {
    cout << "setwise coprime" << endl;
    return;
  }
  int tt = gcd_pairs(a, n);
  if (tt == n * (n - 1) / 2) {
    cout << "pairwise coprime" << endl;
  } else
    cout << "setwise coprime" << endl;
}

int main() {
  SPEED
  ll t = 1;

  while (t--)
    solve();
}