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

#include <bits/stdc++.h>

#define EB emplace_back
#define int long long
#define F first
#define S second
// #define N 500005a
#define all(x) x.begin(), x.end()
#define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

using namespace std;

bool is_prime(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
const int N = 1e6 + 10;
int mp[N] = {};

int32_t main() {
  IOS;
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    int A[n];

    vector<int> primes;
    for (int i = 2; i < 1100; i++) {
      if (is_prime(i))
        primes.EB(i);
    }

    int g = 0;
    for (int i = 0; i < n; i++) {
      cin >> A[i];
      g = __gcd(A[i], g);
      if (A[i] == 1)
        continue;
      bool ok = true;
      for (auto x : primes) {
        if (A[i] % x == 0) {
          ok = false;
          mp[x]++;
          if (A[i] / x != x && x != A[i]) {
            mp[A[i] / x]++;
          }
        }
      }
      if (ok)
        mp[A[i]]++;
    }
    bool flag = true;

    for (auto x : mp) {
      if (x > 1) {
        flag = 0;
        break;
      }
    }

    if (flag) {
      cout << "pairwise coprime" << endl;
      break;
    }

    if (g == 1) {
      cout << "setwise coprime" << endl;
      break;
    }

    cout << "not coprime";
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(), x.end()
#define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

using namespace std;

bool is_prime(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int32_t main() {
  IOS;
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    int A[n];
    int mp[N];
    vector<int> primes;
    for (int i = 2; i < 1100; i++) {
      if (is_prime(i))
        primes.EB(i);
    }

    int g = 0;
    for (int i = 0; i < n; i++) {
      cin >> A[i];
      g = __gcd(A[i], g);
      if (A[i] == 1)
        continue;
      bool ok = true;
      for (auto x : primes) {
        if (A[i] % x == 0) {
          ok = false;
          mp[x]++;
          if (A[i] / x != x && x != A[i]) {
            mp[A[i] / x]++;
          }
        }
      }
      if (ok)
        mp[A[i]]++;
    }
    bool flag = true;

    for (auto x : mp) {
      if (x > 1) {
        flag = 0;
        break;
      }
    }

    if (flag) {
      cout << "pairwise coprime" << endl;
      break;
    }

    if (g == 1) {
      cout << "setwise coprime" << endl;
      break;
    }

    cout << "not coprime";
  }
  return 0;
}