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

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

vector<bool> is_prime;
vector<bool> is_prime_small;

ll res[10000];

// 約数の列挙O(√n)
ll divisor(ll n) {
  ll ret = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res[ret++] = (i);
      if (i != n / i) {
        res[ret++] = (n / i);
      }
    }
  }
  return ret;
}

// a > b
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

void solve(long long N, std::vector<long long> A) {
  is_prime.resize(0);
  for (int i = 0; i <= 1e6; i++) {
    is_prime.push_back(true);
  }
  is_prime[0] = is_prime[1] = false;
  ll n = divisor(A[0]);
  REP(k, n) {
    ll i = res[k];
    if (is_prime[i]) {
      for (int j = i; j <= 1e6; j += i) {
        is_prime[j] = false;
      }
    }
  }
  ll count = 0;
  FOR(j, 1, N) {
    if (A[j] == 1) {
      continue;
    }
    if (is_prime[A[j]]) {
      ll n = divisor(A[j]);
      REP(k, n) {
        ll i = res[k];
        if (is_prime[i]) {
          for (int j = i; j <= 1e6; j += i) {
            is_prime[j] = false;
          }
        }
      }
    } else {
      count++;
    }
  }
  if (count == 0) {
    cout << "pairwise coprime" << endl;
    return;
  }
  int x = A[0];
  FOR(j, 1, N) {
    if (x > A[j]) {
      x = gcd(x, A[j]);
    } else {
      x = gcd(A[j], x);
    }
  }
  if (x == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Error: 0

Fixed submission:

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

vector<bool> is_prime;
vector<bool> is_prime_small;

// 約数の列挙O(√n)
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) {
        res.push_back(n / i);
      }
    }
  }
  return res;
}

// a > b
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

void solve(long long N, std::vector<long long> A) {
  is_prime.resize(0);
  for (int i = 0; i <= 1e6; i++) {
    is_prime.push_back(true);
  }
  is_prime[0] = is_prime[1] = false;
  auto v = divisor(A[0]);
  for (auto i : v) {
    if (is_prime[i]) {
      for (int j = i; j <= 1e6; j += i) {
        is_prime[j] = false;
      }
    }
  }
  ll count = 0;
  FOR(j, 1, N) {
    if (A[j] == 1) {
      continue;
    }
    if (is_prime[A[j]]) {
      auto v = divisor(A[0]);
      for (auto i : v) {
        if (is_prime[i]) {
          for (int j = i; j <= 1e6; j += i) {
            is_prime[j] = false;
          }
        }
      }
    } else {
      count++;
    }
  }
  if (count == 0) {
    cout << "pairwise coprime" << endl;
    return;
  }
  int x = A[0] / 0;
  FOR(j, 1, N) {
    if (x > A[j]) {
      x = gcd(x, A[j]);
    } else {
      x = gcd(A[j], x);
    }
  }
  if (x == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}