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

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
// const long long MOD = 998244353;
const long long INF_LL = 1e18 + 11;
const int INF_int = 1e9 + 11;
#define ll long long
#define mp std::make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define lrep(i, n) for (long long i = 0; i < n; i++)
#define All(a) a.begin(), a.end()
#define Debug_Output_ALL(a)                                                    \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl;
// 最大公約数
long long gcd(long long a, long long b) {
  if (a < b)
    swap(a, b);
  while (a % b != 0) {
    swap(a, b);
    b = b % a;
  }
  return b;
}
vector<ll> makeprimes(long n) {
  bool judge[n + 1];
  for (int i = 0; i <= n; i++) {
    judge[i] = true;
  }
  vector<ll> prime;
  for (int i = 2; i <= n; i++) {
    if (judge[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        judge[j] = false;
      }
      prime.push_back(i); // ここでprimeに入れられる素数の条件を指定できる
    }
  }
  return prime;
}
int main() {
  int n;
  cin >> n;
  vector<ll> a;
  rep(i, n) {
    ll b;
    cin >> b;
    a.push_back(b);
  }
  ll t = a[0];
  for (int i = 1; i < n; i++)
    t = gcd(t, a[i]);
  if (t != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<ll> primes = makeprimes(1003);
  int s = primes.size();
  vector<int> vec(s);
  fill(All(vec), 0);
  bool fl = true;
  set<int> st;
  rep(i, n) {
    rep(j, s) {
      ll now = primes[j];
      if (a[i] % now == 0)
        vec[j]++;
      while (a[i] % now == 0) {
        a[i] /= now;
      }
    }
    if (st.empty())
      st.insert(a[i]);
    else if (a[i] != 1) {
      if (st.count(a[i]) != 0) {
        fl = false;
      } else {
        st.insert(a[i]);
      }
    }
  }
  rep(i, s) {
    if (vec[i] >= 2)
      fl = false;
  }
  if (fl)
    cout << "pairwise coprime" << endl;
  else
    cout << "setwise coprime" << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
// const long long MOD = 998244353;
const long long INF_LL = 1e18 + 11;
const int INF_int = 1e9 + 11;
#define ll long long
#define mp std::make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define lrep(i, n) for (long long i = 0; i < n; i++)
#define All(a) a.begin(), a.end()
#define Debug_Output_ALL(a)                                                    \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl;
// 最大公約数
long long gcd(long long a, long long b) {
  if (a < b)
    swap(a, b);
  while (a % b != 0) {
    swap(a, b);
    b = b % a;
  }
  return b;
}
vector<ll> makeprimes(long n) {
  bool judge[n + 1];
  for (int i = 0; i <= n; i++) {
    judge[i] = true;
  }
  vector<ll> prime;
  for (int i = 2; i <= n; i++) {
    if (judge[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        judge[j] = false;
      }
      prime.push_back(i); // ここでprimeに入れられる素数の条件を指定できる
    }
  }
  return prime;
}
int main() {
  int n;
  cin >> n;
  vector<ll> a;
  rep(i, n) {
    ll b;
    cin >> b;
    a.push_back(b);
  }
  ll t = a[0];
  for (int i = 1; i < n; i++)
    t = gcd(t, a[i]);
  if (t != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<ll> primes = makeprimes(1003);
  int s = primes.size();
  vector<int> vec(s);
  fill(All(vec), 0);
  bool fl = true;
  set<int> st;
  rep(i, n) {
    rep(j, s) {
      ll now = primes[j];
      if (a[i] % now == 0)
        vec[i]++;
      while (a[i] % now == 0) {
        a[i] /= now;
      }
    }
    if (st.empty())
      st.insert(a[i]);
    else if (a[i] != 1) {
      if (st.count(a[i]) != 0) {
        fl = false;
      } else {
        st.insert(a[i]);
      }
    }
  }
  rep(i, s) {
    if (vec[i] >= 2)
      fl = false;
  }
  if (fl)
    cout << "pairwise coprime" << endl;
  else
    cout << "setwise coprime" << endl;
}