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

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _ % MOD
#define __ %= MOD

#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))

#define swap(a, b)                                                             \\
  {                                                                            \\
    a = a + b;                                                                 \\
    b = a - b;                                                                 \\
    a = a - b;                                                                 \\
  }
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
} // modular exponent
const int maxn = 1e6 + 1;
ll sieve[maxn];
map<ll, ll> pfq;
int main() {
  ios_base::sync_with_stdio(false); // don't use printf and scanf
  cin.tie(NULL);                    // cout<<fixed<<setprecision
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  repA(i, 1, n) cin >> a[i];
  ll gd = 0;
  for (ll i = 2; i < maxn; i++) {
    if (sieve[i] == 0) {
      sieve[i] = i; // largest prime factor of a number
      for (ll j = 2; j * i < maxn; j++) {
        sieve[j * i] = i;
      }
    }
  }
  repA(i, 1, n) {
    ll val = a[i];
    gd = gcd(gd, val);
    set<ll> st;
    while (val > 1) {
      if (st.count(sieve[val]) == 0)
        pfq[sieve[val]]++;
      st.insert(sieve[val]);
      val /= sieve[val];
    }
  }
  int flag = 1;
  for (auto it : pfq) {
    if (it.se > 1) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime\\n";
    return 0;
  } else {
    if (gd == 1) {
      cout << "setwise coprime\\n";
      return 0;
    } else {
      cout << "not coprime\\n";
      return 0;
    }
  }
  return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _ % MOD
#define __ %= MOD

#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))

#define swap(a, b)                                                             \\
  {                                                                            \\
    a = a + b;                                                                 \\
    b = a - b;                                                                 \\
    a = a - b;                                                                 \\
  }
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
} // modular exponent
const int maxn = 1e6;
ll sieve[maxn];
map<ll, ll> pfq;
int main() {
  ios_base::sync_with_stdio(false); // don't use printf and scanf
  cin.tie(NULL);                    // cout<<fixed<<setprecision
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  repA(i, 1, n) cin >> a[i];
  ll gd = 0;
  for (ll i = 2; i < maxn; i++) {
    if (sieve[i] == 0) {
      sieve[i] = i; // largest prime factor of a number
      for (ll j = 2; j * i < maxn; j++) {
        sieve[j * i] = i;
      }
    }
  }
  repA(i, 1, n) {
    ll val = a[i];
    gd = gcd(gd, val);
    set<ll> st;
    while (val > 1) {
      if (st.count(sieve[val]) == 0)
        pfq[sieve[val]]++;
      st.insert(sieve[val]);
      val /= sieve[val];
    }
  }
  int flag = 1;
  for (auto it : pfq) {
    if (it.se > 1) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime\\n";
    return 0;
  } else {
    if (gd == 1) {
      cout << "setwise coprime\\n";
      return 0;
    } else {
      cout << "not coprime\\n";
      return 0;
    }
  }
  return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!