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

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

#define mx 1000006
#define ll long long
int n, m, mm, tc = 1, sz;
int cnt[2 * mx];
vector<int> pr;
bool pairwise, setwise, atLeastOne;

void sieve(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  for (int p = 2; p <= n; p++)
    if (prime[p])
      pr.push_back(p);
}

void primeFactor(int x) {
  // cout << "Here is : " << x << "\\n";
  int X = x;
  for (auto it : pr) {
    if (it * it > X || x == 1)
      break;
    if (x % it == 0) {
      cnt[it]++;
      if (cnt[it] > 1) {
        pairwise = 1;
      }
      while (x % it == 0) {
        // cout << it << " ";
        x /= it;
      }
    }
  }
  if (x > 1) {
    cnt[x]++;
    if (cnt[x] > 1) {
      pairwise = 1;
    }
    // cout << x << " ";
  }
  // exit(0);
}

void solve(int kk) {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int aa;
    cin >> aa;
    primeFactor(aa);
  }
  for (auto it : pr) {
    if (cnt[it] == n)
      atLeastOne = 1;
  }
  if (!pairwise)
    cout << "pairwise coprime\\n";
  else
    (!atLeastOne) ? cout << "setwise coprime\\n" : cout << "not coprime\\n";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("D:\\\\Codings\\\\CPP\\\\input.in", "r", stdin);
  freopen("D:\\\\Codings\\\\CPP\\\\output.in", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int kk = 0;
  sieve(1e6);
  while (++kk <= tc)
    solve(kk);

  return 0;
}

Error: WA

Fixed submission:

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

#define mx 1000006
#define ll long long
int n, m, mm, tc = 1, sz;
int cnt[mx];
vector<int> pr;
bool pairwise, setwise, atLeastOne;

bool ifnotPrime(int prime[], int x) {
  return (prime[x / 64] & (1 << ((x >> 1) & 31)));
}

bool makeComposite(int prime[], int x) {
  prime[x / 64] |= (1 << ((x >> 1) & 31));
}

void bitWiseSieve(int n) {
  int prime[n / 64];
  memset(prime, 0, sizeof(prime));

  for (int i = 3; i * i <= n; i += 2) {
    if (!ifnotPrime(prime, i))
      for (int j = i * i, k = i << 1; j < n; j += k)
        makeComposite(prime, j);
  }

  pr.push_back(2);

  for (int i = 3; i <= n; i += 2)
    if (!ifnotPrime(prime, i))
      pr.push_back(i);
}

void primeFactor(int x) {
  // cout << "Here is : " << x << "\\n";
  int X = x;
  for (int i = 0; i < sz && pr[i] * pr[i] <= X; i++) {
    if (x % pr[i] == 0) {
      cnt[pr[i]]++;
      if (cnt[pr[i]] > 1) {
        pairwise = 1;
      }
      while (x % pr[i] == 0) {
        // cout << pr[i] << " ";
        x /= pr[i];
      }
    }
  }
  if (x > 1) {
    cnt[x]++;
    if (cnt[x] > 1) {
      pairwise = 1;
    }
    // cout << x << " ";
  }
  // exit(0);
}

void solve(int kk) {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int aa;
    cin >> aa;
    primeFactor(aa);
  }
  for (auto it : pr) {
    if (cnt[it] == n)
      atLeastOne = 1;
  }
  if (!pairwise)
    cout << "pairwise coprime\\n";
  else
    (!atLeastOne) ? cout << "setwise coprime\\n" : cout << "not coprime\\n";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("D:\\\\Codings\\\\CPP\\\\input.in", "r", stdin);
  freopen("D:\\\\Codings\\\\CPP\\\\output.in", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int kk = 0;
  bitWiseSieve(1e6);
  sz = pr.size();
  while (++kk <= tc)
    solve(kk);

  return 0;
}