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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...)                                                               \\
  cout << #__VA_ARGS__ ": [";                                                  \\
  for (auto e : __VA_ARGS__) {                                                 \\
    cout << e << ", ";                                                         \\
  }                                                                            \\
  cout << "]\\n"
#define dbg1(...) cout << #__VA_ARGS__ " " << __VA_ARGS__
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
constexpr ll R = 2e6 + 69, INF = 2e9 + 6969;

int n, A[R], D, M, lp[R];
vector<int> p;
set<int> s;
int NWD(int a, int b) {
  while (a > 0 && b > 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
    M = max(M, A[i]);
  }
  D = A[0];
  for (int i = 1; i < n; ++i)
    D = NWD(A[i], D);
  if (D > 1) {
    puts("not coprime");
    return 0;
  }
  for (int i = 2; i <= M; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      p.pb(i);
    }
    for (int j = 0; j < p.size() && i * p[j] <= M && p[j] <= lp[i]; ++j) {
      lp[i * p[j]] = p[j];
    }
  }
  bool ok = 1;
  for (int i = 0; i < n; ++i) {
    int x = A[i];
    //  int d = INF;
    set<int> pom;
    pom.clear();
    while (x > 1) {
      //  if(d!=lp[x])
      //  {
      //  d = lp[x];
      //  if(s.count(d))
      //  {
      //  ok = 0;
      //  break;
      //  }
      //  s.insert(d);
      //  }
      pom.insert(lp[x]);
      x /= lp[x];
    }
    for (auto e : pom) {
      if (s.count(e)) {
        ok = 0;
        break;
      }
      s.insert(e);
    }
    if (!ok)
      break;
  }
  puts(ok ? "pairwise coprime" : "setwise coprime");
  return 0;
}


Error: 0

Fixed submission:

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...)                                                               \\
  cout << #__VA_ARGS__ ": [";                                                  \\
  for (auto e : __VA_ARGS__) {                                                 \\
    cout << e << ", ";                                                         \\
  }                                                                            \\
  cout << "]\\n"
#define dbg1(...) cout << #__VA_ARGS__ " " << __VA_ARGS__
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
constexpr ll R = 2e5 + 69, INF = 2e9 + 6969;

int n, A[R], D, M, lp[R];
vector<int> p;
set<int> s;
int NWD(int a, int b) {
  while (a > 0 && b > 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
    M = max(M, A[i]);
  }
  D = A[0];
  for (int i = 1; i < n; ++i)
    D = NWD(A[i], D);
  if (D > 1) {
    puts("not coprime");
    return 0;
  }
  for (int i = 2; i <= M; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      p.pb(i);
    }
    for (int j = 0; j < p.size() && i * p[j] <= M && p[j] <= lp[i]; ++j) {
      lp[i * p[j]] = p[j];
    }
  }
  bool ok = 1;
  for (int i = 0; i < n; ++i) {
    int x = A[i];
    int d = INF;
    while (x > 1) {
      if (d != lp[x]) {
        d = lp[x];
        if (s.count(d)) {
          ok = 0;
          break;
        }
        s.insert(d);
      }
      x /= lp[x];
    }
    if (!ok)
      break;
  }
  puts(ok ? "pairwise coprime" : "setwise coprime");
  return 0;
}