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

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1 * INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1 * LLINF;

template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
                                  Container const &x) {
  os << "{ ";
  for (auto &y : x)
    os << y << " ";
  return os << "}";
}

template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
  return os << "[ " << p.first << ", " << p.second << "]";
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;

#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define exists(x, m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

vll primes_up_to(ll lim) {
  vll primes = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29,
                31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
  if (lim <= 71)
    return {primes.begin(), upper_bound(all(primes), lim)};
  for (int num = 73; num <= lim; num++) {
    bool is_prime = true;
    for (int i = 0; primes[i] * primes[i] <= num; i++) {
      if (num % primes[i] == 0) {
        is_prime = false;
        break;
      }
    }
    if (is_prime)
      primes.pb(num);
  }
  return primes;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi A = vi();
  int maxx = 0;
  rep(i, n) {
    int x;
    cin >> x;
    A.pb(x);
    maxx = max(maxx, x);
  }
  vll primes = primes_up_to(1e6);
  map<int, int> prime_freq = map<int, int>();
  for (const int &a : A) {
    int b = a;
    for (int i = 0; primes[i] * primes[i] <= b; i++) {
      if (b % primes[i] == 0)
        prime_freq[primes[i]]++;
      while (b % primes[i] == 0)
        b /= primes[i];
    }
    if (b != 1)
      prime_freq[b]++;
  }
  int max_freq = 0;
  for (const auto &[p, freq] : prime_freq) {
    max_freq = max(max_freq, freq);
  }
  if (max_freq <= 1) {
    cout << "pairwise coprime";
  } else {
    cout << (max_freq < n ? "setwise coprime" : "not coprime");
  }
}

Error: WA

Fixed submission:

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1 * INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1 * LLINF;

template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
                                  Container const &x) {
  os << "{ ";
  for (auto &y : x)
    os << y << " ";
  return os << "}";
}

template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
  return os << "[ " << p.first << ", " << p.second << "]";
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;

#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define exists(x, m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

vll primes_up_to(ll lim) {
  vll primes = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29,
                31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
  if (lim <= 71)
    return {primes.begin(), upper_bound(all(primes), lim)};
  for (int num = 73; num <= lim; num++) {
    bool is_prime = true;
    for (int i = 0; primes[i] * primes[i] <= num; i++) {
      if (num % primes[i] == 0) {
        is_prime = false;
        break;
      }
    }
    if (is_prime)
      primes.pb(num);
  }
  return primes;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi A = vi();
  int maxx = 0;
  rep(i, n) {
    int x;
    cin >> x;
    A.pb(x);
    maxx = max(maxx, x);
  }
  vll primes = primes_up_to(maxx);
  map<int, int> prime_freq = map<int, int>();
  for (const int &a : A) {
    int b = a;
    for (int i = 0; primes[i] * primes[i] <= b; i++) {
      if (b % primes[i] == 0)
        prime_freq[primes[i]]++;
      while (b % primes[i] == 0)
        b /= primes[i];
    }
    if (b != 1)
      prime_freq[b]++;
  }
  int max_freq = 0;
  for (const auto &[p, freq] : prime_freq) {
    max_freq = max(max_freq, freq);
  }
  if (max_freq <= 1) {
    cout << "pairwise coprime";
  } else {
    cout << (max_freq < n ? "setwise coprime" : "not coprime");
  }
}