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

// The Doc

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define pb push_back
ll mod1 = pow(10, 9) + 7;
int mod2 = 998244353;
ll inf = 1e9;
ll maxxy = 1e6 + 9;
typedef long double ld;
const double PI = 3.141592653589793238;

ll power(ll x, ll y, ll pp) {
  ll res = 1;
  x = x % pp;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % pp;
    y = y >> 1;
    x = (x * x) % pp;
  }
  return res;
}

ll modInverse(ll n, ll pp) { return power(n, pp - 2, pp); }
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll x = a[0];
  for (int i = 1; i < n; ++i) {
    x = gcd(a[i], x);
  }
  // cout<<x<<"\\n";
  if (x != 1) {
    cout << "not coprime"
         << "\\n";
  } else {
    vector<ll> minPrime(1e6 + 1, 0);
    for (int i = 2; i * i <= 1e6; ++i) {
      if (minPrime[i] == 0) {
        for (int j = i * i; j <= 1e6; j += i) {
          if (minPrime[j] == 0) {
            minPrime[j] = i;
          }
        }
      }
    }
    for (int i = 2; i <= 1e6; ++i) {
      if (minPrime[i] == 0) {
        minPrime[i] = i;
      }
    }
    vector<ll> ct(1e6 + 1, 0);
    for (int i = 0; i < n; ++i) {
      set<ll> sett;
      while (a[i] != 1) {
        if (minPrime[a[i]] != 1)
          sett.insert(minPrime[a[i]]);
        a[i] /= minPrime[a[i]];
      }
      set<ll>::iterator itr;
      for (itr = sett.begin(); itr != sett.end(); ++itr) {
        ll kkk = *itr;
        // cout<<kkk<<" ";
        ct[kkk]++;
      }
      sett.clear();
    }
    // cout<<ct[2]<<" "<<ct[3]<<"\\n";
    sort(ct.begin(), ct.end());
    // cout<<ct[n]<<"\\n";
    if (ct[1e6] <= 1) {
      cout << "pairwise coprime"
           << "\\n";
    } else {
      cout << "setwise coprime"
           << "\\n";
    }
  }
  return 0;
}


Error: -8

Fixed submission:

// The Doc

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define pb push_back
ll mod1 = pow(10, 9) + 7;
int mod2 = 998244353;
ll inf = 1e9;
ll maxxy = 1e6 + 9;
typedef long double ld;
const double PI = 3.141592653589793238;

ll power(ll x, ll y, ll pp) {
  ll res = 1;
  x = x % pp;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % pp;
    y = y >> 1;
    x = (x * x) % pp;
  }
  return res;
}

ll modInverse(ll n, ll pp) { return power(n, pp - 2, pp); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll x = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i == 0) {
      x = a[i];
    } else {
      x = __gcd(x, a[i]);
    }
  }
  cout << x << "\\n";
  if (x != 1) {
    cout << "not coprime"
         << "\\n";
  } else {
    vector<ll> minPrime(1e6 + 1, 0);
    for (int i = 2; i * i <= 1e6; ++i) {
      if (minPrime[i] == 0) {
        for (int j = i * i; j <= 1e6; j += i) {
          if (minPrime[j] == 0) {
            minPrime[j] = i;
          }
        }
      }
    }
    for (int i = 2; i <= n; ++i) {
      if (minPrime[i] == 0) {
        minPrime[i] = i;
      }
    }
    vector<ll> ct(1e6 + 1, 0);
    for (int i = 0; i < n; ++i) {
      set<ll> sett;
      while (a[i] != 1) {
        sett.insert(minPrime[a[i]]);
        a[i] /= minPrime[a[i]];
      }
      set<ll>::iterator itr;
      for (itr = sett.begin(); itr != sett.end(); ++itr) {
        ll kkk = *itr;
        ct[kkk]++;
      }
      sett.clear();
    }
    sort(ct.begin(), ct.end());
    if (ct[n] >= 1) {
      cout << "pairwise coprime"
           << "\\n";
    } else {
      cout << "setwise coprime"
           << "\\n";
    }
  }
  return 0;
}