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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i, n) for (int i = 0; i < n; ++i)
#define fi(i, st, n) for (int i = st; i <= n; ++i)
#define veci vector<int>
#define vecp vector<pair<int, int>>
#define vecl vector<ll>
int prime[1000000 + 10];

ll lcm(ll a, ll b) { return a * b / __gcd(a, b); }

ll power(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    n = n / 2;
  }
  return res;
}

ll sum(int arr[], int n) {
  ll res = 0;
  f(i, n) { res += arr[i]; }
  return res;
}

void seive() {
  prime[1] = 0;
  for (int i = 2; i <= 1000000; i++) {
    prime[i] = 1;
  }
  for (ll i = 2; i <= 1000000; i++) {
    if (prime[i] == 1) {
      for (ll j = 2 * i; j <= 1000000; j += i) {
        prime[j] = i;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //	cin>>t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    f(i, n) cin >> arr[i];
    int ans = 0;
    f(i, n) ans = __gcd(ans, arr[i]);
    if (ans > 1) {
      cout << "not coprime\\n";
    } else {
      int c = 0;
      f(i, n) if (arr[i] == 1) c++;
      if (n > 100000 + c) {
        cout << "setwise coprime\\n";
      } else {
        int flag = 0;
        sort(arr, arr + n);
        int check[1000000 + 10] = {0};
        for (int i = 0; i < n; i++) {
          int temp = arr[i];
          if (temp != 1) {
            for (int j = 2; j <= sqrt(arr[i]); j++) {
              if (temp % j == 0) {
                if (check[j] or check[temp / j]) {
                  flag = 1;
                  break;
                }
                check[j] = 1;
                check[temp / j] = 1;
              }
            }
            if (flag)
              break;
            if (check[arr[i]]) {
              flag = 1;
              break;
            }
            check[arr[i]] = 1;
          }
        }
        if (flag)
          cout << "setwise coprime\\n";
        else
          cout << "pairwise coprime\\n";
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i, n) for (int i = 0; i < n; ++i)
#define fi(i, st, n) for (int i = st; i <= n; ++i)
#define veci vector<int>
#define vecp vector<pair<int, int>>
#define vecl vector<ll>
int prime[1000000 + 10];

ll lcm(ll a, ll b) { return a * b / __gcd(a, b); }

ll power(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    n = n / 2;
  }
  return res;
}

ll sum(int arr[], int n) {
  ll res = 0;
  f(i, n) { res += arr[i]; }
  return res;
}

void seive() {
  prime[1] = 0;
  for (int i = 2; i <= 1000000; i++) {
    prime[i] = 1;
  }
  for (ll i = 2; i <= 1000000; i++) {
    if (prime[i] == 1) {
      for (ll j = 2 * i; j <= 1000000; j += i) {
        prime[j] = i;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //	cin>>t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    f(i, n) cin >> arr[i];
    int ans = 0;
    f(i, n) ans = __gcd(ans, arr[i]);
    if (ans > 1) {
      cout << "not coprime\\n";
    } else {
      int c = 0;
      f(i, n) if (arr[i] == 1) c++;
      if (n > 100000 + c) {
        cout << "setwise coprime\\n";
      } else {
        int flag = 0;
        sort(arr, arr + n);
        int check[100000 + 10] = {0};
        for (int i = 0; i < n; i++) {
          int temp = arr[i];
          if (temp != 1) {
            for (int j = 2; j <= sqrt(arr[i]); j++) {
              if (temp % j == 0) {
                if (check[j] or check[temp / j]) {
                  flag = 1;
                  break;
                }
                check[j] = 1;
                check[temp / j] = 1;
              }
            }
            if (flag)
              break;
            if (check[arr[i]]) {
              flag = 1;
              break;
            }
            check[arr[i]] = 1;
          }
        }
        if (flag)
          cout << "setwise coprime\\n";
        else
          cout << "pairwise coprime\\n";
      }
    }
  }
  return 0;
}