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

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define IN(a, b) (a.find(b) != a.end())
#define p(a, b) make_pair(a, b)
#define readVec(a)                                                             \\
  for (int64_t __i = 0; __i < (int64_t)a.size(); __i++) {                      \\
    cin >> a[__i];                                                             \\
  }

// jimjam

template <typename T> void pMin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T> void pMax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &c);
template <typename A, typename B>
std::ostream &operator<<(std::ostream &os, const std::pair<A, B> &c) {
  std::cout << "(" << c.first << ", " << c.second << ")";
  return os;
}
using namespace std;

int64_t numFactors[1000005];
bool flag = false;
void sieve(int64_t k) {
  for (int64_t i = 1; i * i <= k; i++) {
    // assert(i<k);
    if (k % i == 0) {
      int64_t a = i;
      int64_t b = k / i;
      assert(max(a, b) < 1000005);
      if (numFactors[a] && a != 1) {
        flag = true;
        return;
      }
      numFactors[a]++;
      if (a != b) {
        if (numFactors[b]) {
          flag = true;
          return;
        }
        numFactors[b]++;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  readVec(a);
  for (int64_t i : a) {
    sieve(i);
  }
  int64_t curr = a[0];
  for (int64_t i = 1; i < n; i++) {
    curr = __gcd(curr, a[i]);
  }

  if (!flag) {
    cout << "pairwise coprime" << endl;
  } else if (curr == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define IN(a, b) (a.find(b) != a.end())
#define p(a, b) make_pair(a, b)
#define readVec(a)                                                             \\
  for (int64_t __i = 0; __i < (int64_t)a.size(); __i++) {                      \\
    cin >> a[__i];                                                             \\
  }

// jimjam

template <typename T> void pMin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T> void pMax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &c);
template <typename A, typename B>
std::ostream &operator<<(std::ostream &os, const std::pair<A, B> &c) {
  std::cout << "(" << c.first << ", " << c.second << ")";
  return os;
}
using namespace std;

int64_t numFactors[1000005];
bool flag = false;
void sieve(int64_t k) {
  for (int64_t i = 1; i * i <= k; i++) {
    assert(i < k);
    if (k % i == 0) {
      int64_t a = i;
      int64_t b = k / i;
      assert(max(a, b) < 1000005);
      if (numFactors[a] && a != 1) {
        flag = true;
        return;
      }
      numFactors[a]++;
      if (a != b) {
        if (numFactors[b]) {
          flag = true;
          return;
        }
        numFactors[b]++;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  readVec(a);
  for (int64_t i : a) {
    sieve(i);
  }
  int64_t curr = a[0];
  for (int64_t i = 1; i < n; i++) {
    curr = __gcd(curr, a[i]);
  }

  if (!flag) {
    cout << "pairwise coprime" << endl;
  } else if (curr == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}