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

#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <map>
#include <vector>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll, ll> P;
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define per(i, n) for ((i) = (n)-1; (i) >= 0; (i)--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define zt(a, b) (max((a), (b)) - min((a), (b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
#define sankaku(x) (((x) * ((x) + 1)) / 2)
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int upint(cv *a, cv *b) {
  return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0;
}
int downint(cv *a, cv *b) {
  return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}
int upchar(cv *left, cv *right) { return strcmp((char *)left, (char *)right); }
int downchar(cv *left, cv *right) {
  return strcmp((char *)right, (char *)left);
}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= a;
      if (mod >= 1)
        res %= mod;
    }
    a *= a;
    if (mod >= 1)
      a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize() {}
int main(void) {
  initialize();
  ll n, m, i, j, k, result = 0;
  int a[LIMIT3] = {0};
  int check[LIMIT3] = {0};
  int dp[LIMIT3] = {0};
  map<ll, ll> prime;
  string s;

  cin >> n;
  k = 0;
  rep(i, n) {
    cin >> a[i];
    dp[a[i]]++;
    k = max(k, a[i]);
  }
  int flag = 0;
  for (i = 2; i <= k; i++) {
    ll sum = 0;
    for (j = i; j <= k; j += i) {
      sum += dp[j];
    }
    if (sum >= 2) {
      flag = 1;
      break;
    }
  }
  if (flag == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll tmp2 = a[0];
  for (i = 1; i < n; i++) {
    tmp2 = gcd(tmp2, a[i]);
  }
  if (tmp2 == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <map>
#include <vector>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define INF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll, ll> P;
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define per(i, n) for ((i) = (n)-1; (i) >= 0; (i)--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define zt(a, b) (max((a), (b)) - min((a), (b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
#define sankaku(x) (((x) * ((x) + 1)) / 2)
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int upint(cv *a, cv *b) {
  return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0;
}
int downint(cv *a, cv *b) {
  return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}
int upchar(cv *left, cv *right) { return strcmp((char *)left, (char *)right); }
int downchar(cv *left, cv *right) {
  return strcmp((char *)right, (char *)left);
}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= a;
      if (mod >= 1)
        res %= mod;
    }
    a *= a;
    if (mod >= 1)
      a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize() {}
int main(void) {
  initialize();
  ll n, m, i, j, k, result = 0;
  int a[LIMIT2] = {0};
  map<ll, ll> dp, prime;
  string s;

  cin >> n;
  k = 0;
  rep(i, n) {
    cin >> a[i];
    k = max(k, a[i]);
  }
  prime[2] = 1;
  for (i = 3; i <= k; i++) {
    prime[i] = 1;
  }
  for (i = 3; i * i <= k; i++) {
    for (j = 3 * i; j <= k; j += 2 * k) {
      prime.erase(j);
    }
  }
  int flag = 0;
  for (const auto &[key, value] : prime) {
    rep(i, n) {
      ll tmp = a[i];
      if (tmp % key == 0 && dp.count(key)) {
        flag = 1;
        break;
      }
      while (tmp % key == 0) {
        dp[key] = 1;
        tmp /= key;
      }
    }
    if (flag == 1)
      break;
  }
  if (flag == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll tmp2 = a[0];
  for (i = 1; i < n; i++) {
    tmp2 = gcd(tmp2, a[i]);
  }
  if (tmp2 == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}