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

// #pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m)                                                                  \\
  for (auto itr = (m).begin(); itr != (m).end(); itr++) {                      \\
    itr->first << " " << itr->second << "\\n";                                  \\
  }
#define int long long int
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define ii pair<int, int>
#define Max 100000 + 5
#define IO                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x)                                                                 \\
  cout << (x) << " ";                                                          \\
  exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mx = 1000000 + 2;
vector<int> spf(mx);
void sieve() {

  for (int i = 2; i <= 1000000; i += 2)
    spf[i] = 2;
  for (int i = 3; i <= 1000000; i += 2)
    spf[i] = i;
  for (int i = 3; i * i <= 1000000; i += 2) {

    if (spf[i] == i) {

      for (int j = 2 * i; j <= 1000000; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}
map<int, int> mp;
bool good(int n) {

  while (n != 1) {

    int pf = spf[n];
    if (mp.find(pf) != mp.end())
      return 0;
    mp[pf] = 1;
    while (n % pf == 0) {
      n /= pf;
    }
  }
  return 1;
}

int32_t main() {
  IO
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  sieve();

  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  bool c1 = 1, c2 = 1;
  int g = __gcd(v[0], v[1]);
  for (int i = 0; i < n; i++) {
    if (c1 and !good(v[i])) {
      c1 = 0;
    }
    g = __gcd(g, v[i]);
  }
  if (g != 1)
    c2 = 0;
  if (c1 == 1) {
    cout << "pairwise coprime";
  } else if (c1 == 0 and c2 == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
}

Error: WA

Fixed submission:

// #pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m)                                                                  \\
  for (auto itr = (m).begin(); itr != (m).end(); itr++) {                      \\
    itr->first << " " << itr->second << "\\n";                                  \\
  }
#define int long long int
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define ii pair<int, int>
#define Max 100000 + 5
#define IO                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x)                                                                 \\
  cout << (x) << " ";                                                          \\
  exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mx = 1000000 + 2;
vector<int> spf(mx);
void sieve() {

  for (int i = 2; i <= 1000000; i += 2)
    spf[i] = 2;
  for (int i = 3; i <= 100000; i += 2)
    spf[i] = i;
  for (int i = 3; i * i <= 1000000; i += 2) {

    if (spf[i] == i) {

      for (int j = 2 * i; j <= 1000000; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}
map<int, int> mp;
bool good(int n) {

  while (n != 1) {

    int pf = spf[n];
    if (mp.find(pf) != mp.end())
      return 0;
    mp[pf] = 1;
    while (n % pf == 0) {
      n /= pf;
    }
  }

  return 1;
}

int32_t main() {
  IO
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  sieve();

  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  bool c1 = 1, c2 = 1;
  int g = __gcd(v[0], v[1]);
  for (int i = 0; i < n; i++) {
    if (c1 and !good(v[i])) {
      c1 = 0;
    }
    g = __gcd(g, v[i]);
  }
  if (g != 1)
    c2 = 0;
  if (c1 == 1) {
    cout << "pairwise coprime";
  } else if (c1 == 0 and c2 == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
}