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

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a, n, t)                                                            \\
  for (int ii = 0; ii < n; ii++)                                               \\
  scanf("%" #t "", &(a)[ii])
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rreps(i, a, n) for (int i = n - 1; i >= a; i--)
#define validl(i, a, b) ((i >= a) && (i <= b)) ? 1 : 0
#define validmat(x, y, a, b, c, d) (validl(x, a, b) && validl(y, a, b)) ? 1 : 0
#define validmn(x, y, m, n) validmat(x, y, 0, m, 0, n)
#define valid(i, n) validl(i, 0, n)
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define mk make_pair
#define pb push_back
#define pa(a, n, t)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
  printf("%" #t "", a[i])
#define p2 pair<int, int>
#define p3 pair<p2, int>
#define fi first
#define se second
#define sd(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define pl(a) printf("%lld", a)
#define pd(a) printf("%d", a)
#define sf(a) scanf("%lf", &a)
#define pf(a) printf("%lf", a)
#define nline printf("\\n")
#define ss(a) scanf("%s", a)
#define ps(a) printf("%s", a)
#define sc(a) scanf("%c", &a)
#define pc(a) printf("%c", &a)
#define mf(m, f) m.find(f) != m.end()
#define pp3(m) cout << m.fi.fi << " " << m.fi.se << " " << m.se << " "
#define pp2(m) cout << m.fi << " " << m.se << " "
#define debug 0
#define MAX 1000000
lli ans = 0;
bool prime[MAX + 1];
int lprime[MAX + 1];
int ar[1000001];
bool traverseondiv(int i) {
  while (i != 1) {
    // cout<<i<<" "<<lprime[i]<<endl;
    int lp = lprime[i];
    if (ar[lp])
      return true;
    while ((i % lp) == 0)
      i = i / lp;
  }
  return false;
}
void adddiv(int i) {
  while (i != 1) {
    int lp = lprime[i];
    ar[lp] = 1;
    while ((i % lp) == 0)
      i = i / lp;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= MAX; p++) {
    // If prime[p] is not changed, then it is a prime
    if (prime[p] == true) {
      // Update all multiples of p greater than or
      // equal to the square of it
      // numbers which are multiple of p and are
      // less than p^2 are already been marked.
      lprime[p] = p;
      for (int i = p * p; i <= MAX; i += p)
        if (prime[i])
          prime[i] = false, lprime[i] = p;
    }
  }

  prime[1] = false;
  lprime[1] = 1;
  rep(i, MAX + 1) if (lprime[i] == 0) lprime[i] = i;
  int n;
  int gcdtill = -1;
  bool pairwise = true;
  cin >> n;
  rep(i, n) {
    int b;
    cin >> b;
    if (traverseondiv(b))
      pairwise = false;
    adddiv(b);
    if (i == 0)
      gcdtill = b;
    else
      gcdtill = __gcd(gcdtill, b);
  }
  if (pairwise)
    cout << "pairwise coprime\\n";
  else if (gcdtill == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a, n, t)                                                            \\
  for (int ii = 0; ii < n; ii++)                                               \\
  scanf("%" #t "", &(a)[ii])
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rreps(i, a, n) for (int i = n - 1; i >= a; i--)
#define validl(i, a, b) ((i >= a) && (i <= b)) ? 1 : 0
#define validmat(x, y, a, b, c, d) (validl(x, a, b) && validl(y, a, b)) ? 1 : 0
#define validmn(x, y, m, n) validmat(x, y, 0, m, 0, n)
#define valid(i, n) validl(i, 0, n)
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define mk make_pair
#define pb push_back
#define pa(a, n, t)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
  printf("%" #t "", a[i])
#define p2 pair<int, int>
#define p3 pair<p2, int>
#define fi first
#define se second
#define sd(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define pl(a) printf("%lld", a)
#define pd(a) printf("%d", a)
#define sf(a) scanf("%lf", &a)
#define pf(a) printf("%lf", a)
#define nline printf("\\n")
#define ss(a) scanf("%s", a)
#define ps(a) printf("%s", a)
#define sc(a) scanf("%c", &a)
#define pc(a) printf("%c", &a)
#define mf(m, f) m.find(f) != m.end()
#define pp3(m) cout << m.fi.fi << " " << m.fi.se << " " << m.se << " "
#define pp2(m) cout << m.fi << " " << m.se << " "
#define debug 0
#define MAX 1000000
lli ans = 0;
bool prime[MAX + 1];
int lprime[MAX + 1];
int ar[1000001];
bool traverseondiv(int i) {
  while (i != 1) {
    // cout<<i<<" "<<lprime[i]<<endl;
    int lp = lprime[i];
    if (ar[lp])
      return true;
    while ((i % lp) == 0)
      i = i / lp;
  }
  return false;
}
void adddiv(int i) {
  while (i != 1) {
    int lp = lprime[i];
    ar[lp] = 1;
    while ((i % lp) == 0)
      i = i / lp;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= MAX; p++) {
    // If prime[p] is not changed, then it is a prime
    if (prime[p] == true) {
      // Update all multiples of p greater than or
      // equal to the square of it
      // numbers which are multiple of p and are
      // less than p^2 are already been marked.
      lprime[p] = p;
      for (int i = p * p; i <= MAX; i += p)
        if (prime[i])
          prime[i] = false, lprime[i] = p;
    }
  }
  prime[1] = false;
  lprime[1] = 1;
  int n;
  int gcdtill = -1;
  bool pairwise = true;
  cin >> n;
  rep(i, n) {
    int b;
    cin >> b;
    if (traverseondiv(b))
      pairwise = false;
    adddiv(b);
    if (i == 0)
      gcdtill = b;
    else
      gcdtill = __gcd(gcdtill, b);
  }
  if (pairwise)
    cout << "pairwise coprime\\n";
  else if (gcdtill == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
  return 0;
}