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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

/*
 *    coder :: ATUL_PANDEY_2608
 *        >>> INDIA <<<
 */
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
#define mod 1000000007
// #define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL), cin.tie(0);
#define listll vector<long long>
#define listi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// end of #define

// define globals ...
const int maxx = 2e5 + 26;

// write function from here ...

bool prime[2008000];
vector<int> prm;

void primes() {
  int n = 2008000;

  memset(prime, true, sizeof(prime));

  for (ll p = 2; p * p <= n; p++) {

    if (prime[p] == true) {

      for (ll i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (int p = 2; p <= n; p++)
    if (prime[p])
      prm.pb(p);
}

int Main() {

  primes();

  int n;
  cin >> n;

  vector<ll> arr(n);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];

    ans = gcd(ans, arr[i]);
  }
  if (ans != 1) {

    cout << "not coprime";
    return 0;
  }

  map<int, int> mp;

  bool flag = 0;

  for (auto it : arr) {

    ll temp = it;

    int i = 0;
    while (true) {

      if (temp % prm[i] == 0) {
        if (mp[prm[i]] == 1)
          flag = 1;
        mp[prm[i]] = 1;
      }
      while (temp % prm[i] == 0) {

        temp /= prm[i];
      }

      if (temp == 1 || prime[temp] == 1) {

        if (temp != 1) {
          if (mp[temp] == 1)
            flag = 1;
          mp[temp] = 1;
        }

        break;
      }
      i++;
    }
  }

  if (flag == 1)
    cout << "setwise coprime";
  else
    cout << "pairwise coprime";

  return 0;
}

int main() {
  quick;
  int t = 1;
  // cin>>t;
  while (t--)
    Main();

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

/*
 *    coder :: ATUL_PANDEY_2608
 *        >>> INDIA <<<
 */
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
#define mod 1000000007
// #define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL), cin.tie(0);
#define listll vector<long long>
#define listi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// end of #define

// define globals ...
const int maxx = 2e5 + 26;

// write function from here ...

bool prime[200800];
vector<int> prm;

void primes() {
  int n = 200800;

  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= n; p++) {

    if (prime[p] == true) {

      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (int p = 2; p <= n; p++)
    if (prime[p])
      prm.pb(p);
}

int Main() {

  primes();

  int n;
  cin >> n;

  vector<ll> arr(n);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];

    ans = gcd(ans, arr[i]);
  }
  if (ans != 1) {

    cout << "not coprime";
    return 0;
  }

  map<int, int> mp;

  bool flag = 0;

  for (auto it : arr) {

    ll temp = it;

    int i = 0;
    while (true) {

      if (temp % prm[i] == 0) {
        if (mp[prm[i]] == 1)
          flag = 1;
        mp[prm[i]] = 1;
      }
      while (temp % prm[i] == 0) {

        temp /= prm[i];
      }
      if (temp == 1 || prime[temp] == 1) {

        if (temp != 1) {
          if (mp[temp] == 1)
            flag = 1;
          mp[temp] = 1;
        }

        break;
      }
      i++;
    }
  }

  if (flag == 1)
    cout << "setwise coprime";
  else
    cout << "pairwise coprime";

  return 0;
}

int main() {
  quick;
  int t = 1;
  // cin>>t;
  while (t--)
    Main();

  return 0;
}