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

#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 5000005
#define endl "\\n"
lli arr[MAX];
bool p[1000005];
lli SPF[1000005];
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int DFS(int s, vector<bool> &visited, vector<vector<lli>> &adj) {
  int ctr = 1;
  visited[s] = true;
  // cout<<s<<endl;
  for (auto i : adj[s]) {
    if (!visited[i])
      ctr += DFS(i, visited, adj);
  }
  return ctr;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  lli t;
  for (lli i = 2; i <= 1000000; i++) {
    if (!p[i]) {
      SPF[i] = i;
      for (lli j = i * i; j <= 1000000; j += i) {
        p[j] = true;
        SPF[j] = i;
      }
    }
  }
  t = 1;
  while (t--) {
    lli n, m;
    cin >> n;
    set<lli> pri;
    lli gcd = 0;
    bool a = true;
    for (int i = 0; i < n; i++)
      cin >> arr[i];
    for (int i = 0; i < n; i++) {
      gcd = __gcd(gcd, arr[i]);
      while (arr[i] > 1) {
        if (pri.count(SPF[arr[i]]))
          a = false;
        else
          pri.insert(SPF[arr[i]]);
        int q = SPF[arr[i]];
        while (arr[i] > 1 && arr[i] % q == 0)
          arr[i] /= q;
      }
    }
    if (a)
      cout << "pairwise coprime" << endl;
    else if (gcd == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\\n"
lli arr[MAX];
bool p[1000000];
lli SPF[1000000];
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int DFS(int s, vector<bool> &visited, vector<vector<lli>> &adj) {
  int ctr = 1;
  visited[s] = true;
  // cout<<s<<endl;
  for (auto i : adj[s]) {
    if (!visited[i])
      ctr += DFS(i, visited, adj);
  }
  return ctr;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  lli t;
  for (lli i = 2; i <= 1000000; i++) {
    if (!p[i]) {
      SPF[i] = i;
      for (lli j = i * i; j <= 1000000; j += i) {
        p[j] = true;
        SPF[j] = i;
      }
    }
  }
  t = 1;
  while (t--) {
    lli n, m;
    cin >> n;
    set<lli> pri;
    lli gcd = 0;
    bool a = true;
    for (int i = 0; i < n; i++)
      cin >> arr[i];
    for (int i = 0; i < n; i++) {
      gcd = __gcd(gcd, arr[i]);
      while (arr[i] > 1) {
        if (pri.count(SPF[arr[i]]))
          a = false;
        else
          pri.insert(SPF[arr[i]]);
        int q = SPF[arr[i]];
        while (arr[i] > 1 && arr[i] % q == 0)
          arr[i] /= q;
      }
    }
    if (a)
      cout << "pairwise coprime" << endl;
    else if (gcd == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
  }
}