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

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define sz(x) (int)x.size()
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solution() {
  const int N = 1000005;
  vi lp(N + 1, 0);
  vector<int> pr;
  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
  int n;
  cin >> n;
  vi c(N + 1, 0);
  bool flag = false;
  int temp;
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (i == 0) {
      gcd = temp;
    } else {
      gcd = __gcd(gcd, temp);
    }
    int x = temp;
    while (x > 1) {
      if (c[lp[x]] > 0) {
        flag = true;
      }
      x /= lp[x];
    }
    x = temp;
    while (x > 1) {
      c[lp[x]]++;
      x /= lp[x];
    }
  }
  if (flag == 1 and gcd == 1) {
    cout << "setwise coprime" << endl;
  } else if (flag == 0 and gcd == 1) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return;
}
int32_t main() {
  run();
  solution();
  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define sz(x) (int)x.size()
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solution() {
  const int N = 1000005;
  int lp[N + 1];
  vector<int> pr;

  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
  int n;
  cin >> n;
  vi c(N + 1, 0);
  bool flag = false;
  int temp;
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (i == 0) {
      gcd = temp;
    } else {
      gcd = __gcd(gcd, temp);
    }
    int x = temp;
    while (x > 1) {
      if (c[lp[x]] > 0) {
        flag = true;
      }
      x /= lp[x];
    }
    x = temp;
    while (x > 1) {
      c[lp[x]]++;
      x /= lp[x];
    }
  }
  if (flag == 1 and gcd == 1) {
    cout << "setwise coprime" << endl;
  } else if (flag == 0 and gcd == 1) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return;
}
int32_t main() {
  run();
  solution();
  return 0;
}