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

// K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long int ll;
typedef long double db;

#define TEST                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define vell vector<ll>
#define pl pair<ll, ll>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x) cerr << #x << ": " << x << endl
#define dbg2(x, y) cerr << #x << ": " << x << " || " << #y << ": " << y << endl

#define endl "\\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007

void solve() {
  ll n;
  cin >> n;
  ll a[n], g = 0;

  vell f(1000002, 0);
  bool ok = true;
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
    g = __gcd(g, a[i]);

    ll x = a[i];

    for (ll j = 2; j * j <= x; ++j) {

      ll c = 0;
      while (x % j == 0) {
        c++;
        x /= j;
      }

      if (c > 0) {
        if (f[j] > 0) {
          ok = false;
        }

        f[j] += c;
      }
    }

    if (x > 1) {
      if (f[x] > 0)
        ok = false;
      f[x]++;
    }
  }

  if (ok) {
    cout << "pairwise coprime";
    return;
  }

  if (g == 1) {
    cout << "setwise coprime";
    return;
  }

  cout << "not coprime";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // TEST
  solve();
}


Error: -11

Fixed submission:

// K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long int ll;
typedef long double db;

#define TEST                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define vell vector<ll>
#define pl pair<ll, ll>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x) cerr << #x << ": " << x << endl
#define dbg2(x, y) cerr << #x << ": " << x << " || " << #y << ": " << y << endl

#define endl "\\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007

void solve() {
  ll n;
  cin >> n;
  ll a[n], g = 0;

  vell f(100000, 0);
  bool ok = true;
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
    g = __gcd(g, a[i]);

    ll x = a[i];

    for (ll j = 2; j * j <= x; ++j) {

      ll c = 0;
      while (x % j == 0) {
        c++;
        x /= j;
      }

      if (c > 0) {
        if (f[j] > 0) {
          ok = false;
        }

        f[j] += c;
      }
    }

    if (x > 1) {
      if (f[x] > 0)
        ok = false;
      f[x]++;
    }
  }

  if (ok) {
    cout << "pairwise coprime";
    return;
  }

  if (g == 1) {
    cout << "setwise coprime";
    return;
  }

  cout << "not coprime";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // TEST
  solve();
}