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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
// Policy based data structure
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
#define ll long long int
#define pii pair<ll, ll>
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define vi vector<ll>
#define vii vector<pii>
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define yes                                                                    \\
  cout << "YES" << endl;                                                       \\
  return;
#define no                                                                     \\
  cout << "NO" << endl;                                                        \\
  return;
#define flus                                                                   \\
  fflush(stdin);                                                               \\
  fflush(stdout);
#define F first
#define S second
#define np next_permutation
#define inf 1e18
#define mod 1000000007
#define N 1000009
#define pi (double)2 * acos(0.0)
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
#define maxpq priority_queue<ll>
void sout() { cout << endl; }
template <typename T, typename... Types> void sout(T var1, Types... var2) {
  cout << var1 << " ";
  sout(var2...);
}
/*******************************************************************/

ll prime[N];
void solve() {
  memset(prime, 0, sizeof prime);
  ll n;
  cin >> n;
  ll a[n];
  rep(i, 0, n) cin >> a[i];
  ll g = 0;
  rep(i, 0, n) { g = __gcd(g, a[i]); }
  if (g != 1) {
    cout << "not coprime" << endl;
    return;
  }
  prime[1] = 1;
  rep(i, 2, N) {
    if (prime[i] != 0)
      continue;
    for (ll j = i; j < N; j += i) {
      if (j >= N or j < 0)
        continue;
      if (prime[j] != 0)
        continue;
      prime[j] = i;
    }
  }
  // rep(i,0,n){
  // 	cout<<a[i]<<" ";
  // }
  // cout<<endl;
  map<int, bool> vis;
  rep(i, 0, n) {
    ll temp = a[i];
    while (temp != 1) {
      if (vis[prime[temp]]) {
        cout << "setwise coprime" << endl;
        return;
      }
      vis[prime[temp]] = true;
      ll x = prime[temp];
      while (temp % x == 0) {
        temp /= x;
      }
    }
  }
  cout << "pairwise coprime" << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
// Policy based data structure
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
#define ll long long int
#define pii pair<ll, ll>
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define vi vector<ll>
#define vii vector<pii>
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define yes                                                                    \\
  cout << "YES" << endl;                                                       \\
  return;
#define no                                                                     \\
  cout << "NO" << endl;                                                        \\
  return;
#define flus                                                                   \\
  fflush(stdin);                                                               \\
  fflush(stdout);
#define F first
#define S second
#define np next_permutation
#define inf 1e18
#define mod 1000000007
#define N 100009
#define pi (double)2 * acos(0.0)
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
#define maxpq priority_queue<ll>
void sout() { cout << endl; }
template <typename T, typename... Types> void sout(T var1, Types... var2) {
  cout << var1 << " ";
  sout(var2...);
}
/*******************************************************************/

ll prime[N];
void solve() {
  memset(prime, 0, sizeof prime);
  ll n;
  cin >> n;
  ll a[n];
  rep(i, 0, n) cin >> a[i];
  ll g = 0;
  rep(i, 0, n) { g = __gcd(g, a[i]); }
  if (g != 1) {
    cout << "not coprime" << endl;
    return;
  }
  prime[1] = 1;
  rep(i, 2, N) {
    if (prime[i] != 0)
      continue;
    prime[i] = 1;
    for (ll j = 2 * i; j < N; j += i) {
      if (j >= N or j < 0)
        continue;
      if (prime[j] != 0)
        continue;
      prime[j] = i;
    }
  }
  // rep(i,0,n){
  // 	cout<<a[i]<<" ";
  // }
  // cout<<endl;
  map<int, bool> vis;
  rep(i, 0, n) {
    ll temp = a[i];
    while (prime[temp] != 1) {
      if (vis[prime[temp]]) {
        cout << "setwise coprime" << endl;
        return;
      }
      vis[prime[temp]] = true;
      temp /= prime[temp];
    }
  }
  cout << "pairwise coprime" << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}