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

#include <bits/stdc++.h>
using namespace std;
#include <numeric>

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define endl "\\n"
#define int long long int
#define mod 1000000007
#define INT_BITS 16
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define INF 10000000
#define pi 3.141592
#define watch(x) cout << (#x) << "=" << (x) << "\\n"
#define pb push_back
// #include "debug.cpp"
//__builtin_popcount

#define MAXN 2000001

// stores smallest prime factor for every number
int spf[MAXN];
int check[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++)

    // marking smallest prime factor for every
    // number to be itself.
    spf[i] = i;

  // separately marking spf for every even
  // number as 2
  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < MAXN; i++) {
    // checking if i is prime
    if (spf[i] == i) {
      // marking SPF for all numbers divisible by i
      for (int j = i * i; j < MAXN; j += i)

        // marking spf[j] if it is not
        // previously marked
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

void getFactorization(int x) {
  set<int> st;
  while (x != 1) {
    st.insert(spf[x]);
    // check[spf[x]]++;
    x = x / spf[x];
  }

  for (auto x : st)
    check[x]++;
}

int32_t main() {
  fast
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
  sieve();
  int n;
  cin >> n;
  int a[n];
  memset(check, 0, sizeof(check));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    getFactorization(a[i]);
  }

  int sw = 1;
  int pw = 1;
  // watch(check[2]);
  for (int i = 2; i < MAXN; ++i) {
    if (check[i] >= n) {
      sw = 0;
    }
    if (check[i] > 1) {
      pw = 0;
    }
  }

  if (pw == 1)
    cout << "pairwise coprime" << endl;
  else {
    if (sw == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <numeric>

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define endl "\\n"
#define int long long int
#define mod 1000000007
#define INT_BITS 16
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define INF 10000000
#define pi 3.141592
#define watch(x) cout << (#x) << "=" << (x) << "\\n"
#define pb push_back
// #include "debug.cpp"
//__builtin_popcount

#define MAXN 100001

// stores smallest prime factor for every number
int spf[MAXN];
int check[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++)

    // marking smallest prime factor for every
    // number to be itself.
    spf[i] = i;

  // separately marking spf for every even
  // number as 2
  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < MAXN; i++) {
    // checking if i is prime
    if (spf[i] == i) {
      // marking SPF for all numbers divisible by i
      for (int j = i * i; j < MAXN; j += i)

        // marking spf[j] if it is not
        // previously marked
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

void getFactorization(int x) {

  while (x != 1) {
    check[spf[x]]++;
    x = x / spf[x];
  }
}

int32_t main() {
  fast
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
  sieve();
  int n;
  cin >> n;
  int a[n];
  memset(check, 0, sizeof(check));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    getFactorization(a[i]);
  }

  int sw = 1;
  int pw = 1;
  // watch(check[2]);
  for (int i = 2; i < 10000; ++i) {
    if (check[i] >= n) {
      sw = 0;
    }
    if (check[i] > 1)
      pw = 0;
  }

  if (pw == 1)
    cout << "pairwise coprime" << endl;
  else {
    if (sw == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
  }
}