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

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int MAX = 1000005;
const int mod = 1000000007;
/* global variables */
// vector<int> cnt(MAX, 0);
vector<int> cnt(MAX, 0);
vector<int> p(MAX);
vector<int> a;
int N;
/* function */
int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
void sieve() {
  // O(Nlog(logN))
  // p[i] = iの持つ最小の素因数を格納
  // ex) p[5] = 5, p[10] = 2
  for (int i = 0; i < MAX; i++)
    p[i] = i;

  for (int i = 2; i * i < MAX; i++) {
    if (p[i] == i) {
      for (int j = i + i; j < MAX; j += i) {
        if (p[j] == j)
          p[j] = i;
      }
    }
  }
}
map<int, int> factrization(int x) {
  // 前処理sieveを行っておく -> O(logx)
  map<int, int> ret;
  while (x != 1) {
    ret[p[x]]++;
    x /= p[x];
  }
  return ret;
}
bool isPc1() {
  for (int i = 0; i < N; i++) {
    cnt[a[i]]++;
  }
  vector<bool> isPrime(MAX, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < MAX; i++) {
    int num = cnt[i];
    if (isPrime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        isPrime[j] = false;
        num += cnt[j];
      }
    }
    if (num >= 2)
      return false;
  }
  return true;
}
bool isPc2() {
  // fast prime factrization
  sieve();
  for (int i = 0; i < N; i++) {
    for (auto q : factrization(a[i])) {
      cnt[q.first]++;
    }
  }
  for (int i = 2; i < MAX; i++)
    if (cnt[i] > 1)
      return false;
  return true;
}
bool isSc() {
  int ret = 0;
  for (int i = 0; i < N; i++) {
    ret = gcd(ret, a[i]);
  }
  if (ret == 1)
    return true;
  else
    return false;
}
/* main */
int main() {
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];

  // if (isPc1()) { cout << "pairwise coprime" << '\\n'; }
  if (isPc2()) {
    cout << "pairwise coprime" << '\\n';
  } else if (isSc()) {
    cout << "setwise coprime" << '\\n';
  } else {
    cout << "not coprime" << '\\n';
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int MAX = 1000005;
const int mod = 1000000007;
/* global variables */
// vector<int> cnt(MAX, 0);
vector<int> cnt(20, 0);
vector<int> p(MAX);
vector<int> a;
int N;
/* function */
int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
void sieve() {
  // O(Nlog(logN))
  // p[i] = iの持つ最小の素因数を格納
  // ex) p[5] = 5, p[10] = 2
  for (int i = 0; i < MAX; i++)
    p[i] = i;

  for (int i = 2; i * i < MAX; i++) {
    if (p[i] == i) {
      for (int j = i + i; j < MAX; j += i) {
        if (p[j] == j)
          p[j] = i;
      }
    }
  }
}
map<int, int> factrization(int x) {
  // 前処理sieveを行っておく -> O(logx)
  map<int, int> ret;
  while (x != 1) {
    ret[p[x]]++;
    x /= p[x];
  }
  return ret;
}
bool isPc1() {
  for (int i = 0; i < N; i++) {
    cnt[a[i]]++;
  }
  vector<bool> isPrime(MAX, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < MAX; i++) {
    int num = cnt[i];
    if (isPrime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        isPrime[j] = false;
        num += cnt[j];
      }
    }
    if (num >= 2)
      return false;
  }
  return true;
}
bool isPc2() {
  // fast prime factrization
  sieve();
  for (int i = 0; i < N; i++) {
    for (auto q : factrization(a[i])) {
      cnt[q.first]++;
    }
  }
  for (int i = 2; i < MAX; i++)
    if (cnt[i] > 1)
      return false;
  return true;
}
bool isSc() {
  int ret = 0;
  for (int i = 0; i < N; i++) {
    ret = gcd(ret, a[i]);
  }
  if (ret == 1)
    return true;
  else
    return false;
}
/* main */
int main() {
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];

  // if (isPc1()) { cout << "pairwise coprime" << '\\n'; }
  if (isPc2()) {
    cout << "pairwise coprime" << '\\n';
  } else if (isSc()) {
    cout << "setwise coprime" << '\\n';
  } else {
    cout << "not coprime" << '\\n';
  }
}