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

// BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }

int primes[505], counter = 0, mark[1200];
int arr[MAX * 10];
int cntPrimes[1000005];
bool found;

void genSieve() {
  int limit = sqrt(1020);
  mark[1] = 1;
  for (int i = 4; i < 1020; i += 2)
    mark[i] = 1;

  primes[counter++] = 2;
  for (int i = 3; i < 1020; i += 2) {
    if (!mark[i]) {
      primes[counter++] = i;
      if (i <= limit) {
        for (int j = i * i; j < 1020; j += i * 2)
          mark[j] = 1;
      }
    }
  }
}

void factorize(int n) {
  int idx = 0, pf = primes[idx];
  while (pf * pf <= n) {
    if (n % pf == 0) {
      while (n % pf == 0) {
        n /= pf;
      }
      if (cntPrimes[pf] > 0) {
        found = true;
        return;
      }
      cntPrimes[pf]++;
    }
    pf = primes[++idx];
  }

  if (n != 1) {
    if (cntPrimes[n] > 0) {
      found = true;
      return;
    }
    cntPrimes[n]++;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  genSieve();
  // cout<<counter<<endl;
  int n;

  cin >> n;

  int g = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (!found)
      factorize(arr[i]);
    g = __gcd(g, arr[i]);
  }

  if (!found)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}


Error: 0

Fixed submission:

// BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }

int primes[505], counter = 0, mark[1200];
int arr[MAX * 10];
int cntPrimes[1000005];
bool found;

void genSieve() {
  int limit = sqrt(1020);
  mark[1] = 1;
  for (int i = 4; i < 1020; i++)
    mark[i] = 1;

  primes[counter++] = 2;
  for (int i = 3; i < 1020; i += 2) {
    if (!mark[i]) {
      primes[counter++] = i;
      if (i <= limit) {
        for (int j = i * i; j < 1020; j += i * 2)
          mark[j] = 1;
      }
    }
  }
}

void factorize(int n) {
  int idx = 0, pf = primes[idx];
  while (pf * pf <= n) {
    if (n % pf == 0) {
      while (n % pf == 0) {
        n /= pf;
      }
      if (cntPrimes[pf] > 0) {
        found = true;
        return;
      }
      cntPrimes[pf]++;
    }
    pf = primes[++idx];
  }

  if (n != 1) {
    if (cntPrimes[n] > 0) {
      found = true;
      return;
    }
    cntPrimes[n]++;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  genSieve();

  int n;

  cin >> n;

  int g = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (!found)
      factorize(arr[i]);
    g = __gcd(g, arr[i]);
  }

  if (!found)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}