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

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

ll gcd(ll n, ll m) { // 最大公約数を求めるプログラム
  // nとmの最大公約数を返す関数
  if (m > n) {
    ll c = n;
    n = m;
    m = c;
  }
  if (n % m == 0ll)
    return m;
  else
    return gcd(m, n % m);
}

vector<ll> fpf_prepare(ll a) { // fpfの前処理　O(alog(loga))
  vector<ll> res(a + 1);
  rp(i, 2, a + 1) {
    if (res[i] == 0) {
      for (int k = 1; i * k <= a; k++) {
        res[i * k] = i;
      }
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  auto D = fpf_prepare(1000010);
  vector<bool> p(1000010, false);
  bool flag = false;
  rp(i, 0, n) {
    ll a;
    scanf("%lld", &a);
    A.at(i) = a;
    ll m = 1000000ll;
    while (a > 1ll) {
      // cout << "a = " << a << " D[a] = " << D[a] << endl;
      if (D[a] < m && p[D[a]])
        flag = true;
      p[D[a]] = true;
      m = D[a];
      a /= D[a];
    }
  }

  if (!flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll g = A[0];
  rp(i, 1, n) {
    g = gcd(g, A[i]);
    if (g == 1) {
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "not coprime" << endl;
  return 0;
}


Error: -11

Fixed submission:

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

ll gcd(ll n, ll m) { // 最大公約数を求めるプログラム
  // nとmの最大公約数を返す関数
  if (m > n) {
    ll c = n;
    n = m;
    m = c;
  }
  if (n % m == 0ll)
    return m;
  else
    return gcd(m, n % m);
}

vector<ll> fpf_prepare(ll a) { // fpfの前処理　O(alog(loga))
  vector<ll> res;
  rp(i, 2, a + 1) {
    if (res[i] == 0) {
      for (int k = 1; i * k <= a; k++) {
        res[i * k] = i;
      }
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  auto D = fpf_prepare(1000010);
  vector<bool> p(1000010, false);
  bool flag = false;
  rp(i, 0, n) {
    ll a;
    scanf("%lld", &a);
    A.at(i) = a;
    ll m = 1000000ll;
    while (a > 1ll) {
      // cout << "a = " << a << " D[a] = " << D[a] << endl;
      if (D[a] < m && p[D[a]])
        flag = true;
      p[D[a]] = true;
      m = D[a];
      a /= D[a];
    }
  }

  if (!flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll g = A[0];
  rp(i, 1, n) {
    g = gcd(g, A[i]);
    if (g == 1) {
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "not coprime" << endl;
  return 0;
}