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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#define vi vector<int>
#define lvi vector<long long>
#define pi pair<int, int>
#define lpi pair<long long, long long>
#define mp make_pair
#define pb push_back
#define ll long long
#define faltu                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000000000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    multiordered_set;
ll int pw(ll int a, ll int b, ll md) {
  if (b == 0)
    return 1;
  ll int t = pw(a, b / 2, md);
  if (b % 2 == 0)
    return (t * t) % mod;
  else
    return ((t * t) % mod * a) % mod;
}
vector<int> pm;
void prm(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p])
      pm.push_back(p);
}
bool cmp(const pair<ll int, ll int> &a, const pair<ll int, ll int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first > b.first;
}
ll int gcd(ll int a, ll int b) {
  if (!a)
    return b;
  return gcd(b % a, a);
}
map<int, int> pa;
int find(int i) {
  if (pa[i] == i)
    return i;
  return pa[i] = find(pa[i]);
}
void join(int i, int j) {
  int a = find(i);
  int b = find(j);
  if (b >= a)
    pa[b] = a;
  else
    pa[a] = b;
}
int isp[1000006];
vector<int> prime;
void getprime(int n) {
  for (int i = 2; i < n; i++) {
    if (isp[i] == -1)
      continue;
    for (int j = 2 * i; j < n; j += i) {
      isp[j] = -1;
    }
    prime.push_back(i);
  }
}
int ddx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int ddy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int vis[1000005];
int main() {
  faltu;
  int t = 1;
  // cin>>t;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 1];
    int g = 0, flag = 0, mx = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      vis[a[i]]++;
      if (!i)
        g = a[i];
      else
        g = gcd(g, a[i]);
      mx = max(mx, a[i]);
    }
    getprime(mx + 1);
    for (int i : prime) {
      int cnt = 0;
      cnt += vis[i];
      for (int j = 2 * i; j < mx + 1; j += i)
        cnt += vis[j];
      if (cnt > 1) {
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      cout << "pairwise coprime\\n";
    else {
      if (g != 1)
        cout << "not coprime\\n";
      else
        cout << "setwise coprime\\n";
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#define vi vector<int>
#define lvi vector<long long>
#define pi pair<int, int>
#define lpi pair<long long, long long>
#define mp make_pair
#define pb push_back
#define ll long long
#define faltu                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000000000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    multiordered_set;
ll int pw(ll int a, ll int b, ll md) {
  if (b == 0)
    return 1;
  ll int t = pw(a, b / 2, md);
  if (b % 2 == 0)
    return (t * t) % mod;
  else
    return ((t * t) % mod * a) % mod;
}
vector<int> pm;
void prm(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p])
      pm.push_back(p);
}
bool cmp(const pair<ll int, ll int> &a, const pair<ll int, ll int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first > b.first;
}
ll int gcd(ll int a, ll int b) {
  if (!a)
    return b;
  return gcd(b % a, a);
}
bool isPrime(int n) {
  if (n <= 1)
    return false;
  for (int i = 2; i < n; i++)
    if (n % i == 0)
      return false;
  return true;
}
map<int, int> pa;
int find(int i) {
  if (pa[i] == i)
    return i;
  return pa[i] = find(pa[i]);
}
void join(int i, int j) {
  int a = find(i);
  int b = find(j);
  if (b >= a)
    pa[b] = a;
  else
    pa[a] = b;
}
int ddx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int ddy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int vis[1000005], cnt[1000005];
int main() {
  faltu;
  int t = 1;
  // cin>>t;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 1];
    int g = 0, flag = 0, mx = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      vis[a[i]] = 1;
      if (!i)
        g = a[i];
      else
        g = gcd(g, a[i]);
      mx = max(mx, a[i]);
    }
    bool pm[n + 1];
    memset(pm, true, sizeof(pm));
    for (int p = 2; p * p <= mx; p++) {
      if (pm[p] == true) {
        if (vis[p] == 1)
          cnt[p]++;
        for (int i = p * p; i <= mx; i += p) {
          if (vis[i] == 1)
            cnt[p]++;
          pm[i] = false;
        }
        if (cnt[p] >= 2) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0)
      cout << "pairwise coprime\\n";
    else {
      if (g != 1)
        cout << "not coprime\\n";
      else
        cout << "setwise coprime\\n";
    }
  }
}