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

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define vvi vector<vi>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
using namespace std;
ll mod = 1e9 + 7;
#define N 100005
vi minprime(1e6 + 1, 0), ffc(1e6 + 1);

void sieve() {
  for (ll i = 2; i * i <= 1e6; i++) {
    if (minprime[i] == 0) {
      for (ll j = i; j <= 1e6; j += i)
        if (minprime[j] == 0)
          minprime[j] = i;
    }
  }
  rep(i, 1, 1e6 + 1) if (minprime[i] == 0) minprime[i] = i;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  // cin>>TESTS;
  // ll cs=1;
  while (TESTS--) {
    ll n;
    cin >> n;
    vi a(n);
    rep(i, 0, n) cin >> a[i];
    sieve();
    rep(i, 0, n) {
      set<ll> fac;
      while (a[i] != 1) {
        fac.insert(minprime[a[i]]);
        a[i] /= minprime[a[i]];
      }
      for (auto &&it : fac) {
        ffc[it]++;
      }
    }
    rep(i, 0, 1e6 + 1) if (ffc[i] == n) {
      cout << "not coprime"
           << "\\n";
      return 0;
    }
    ll fl = 0;
    rep(i, 0, 1e6 + 1) {
      if (ffc[i] > 1)
        fl = 1;
    }
    if (fl == 0)
      cout << "pairwise coprime"
           << "\\n";

    else
      cout << "setwise coprime"
           << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define vvi vector<vi>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
using namespace std;
ll mod = 1e9 + 7;
#define N 100005
vi minprime(1e6 + 1, 0), ffc(1e6 + 1);

void sieve() {
  for (ll i = 2; i * i <= 1e6; i++) {
    if (minprime[i] == 0) {
      for (ll j = i; j <= 1e6; j += i)
        if (minprime[j] == 0)
          minprime[j] = i;
    }
  }
  minprime[1] = 1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  // cin>>TESTS;
  // ll cs=1;
  while (TESTS--) {
    ll n;
    cin >> n;
    vi a(n);
    rep(i, 0, n) cin >> a[i];
    sieve();

    rep(i, 0, n) {
      set<ll> fac;
      while (a[i] != 1) {
        fac.insert(minprime[a[i]]);
        a[i] /= minprime[a[i]];
      }
      for (auto &&it : fac) {
        ffc[it]++;
      }
    }
    rep(i, 0, 1e6 + 1) if (ffc[i] == n) {
      cout << "not coprime"
           << "\\n";
      return 0;
    }
    ll fl = 0;
    rep(i, 0, 1e6 + 1) {
      if (ffc[i] > 1)
        fl = 1;
    }
    if (fl == 0)
      cout << "pairwise coprime"
           << "\\n";

    else
      cout << "setwise coprime"
           << "\\n";
  }
  return 0;
}