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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main() {

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool st = true, pr = true;

  sort(all(a));
  int i = 2;
  int num = a[0];
  vector<int> p;
  while (i * i <= num) {
    if (num % i == 0) {
      while (true) {
        num /= i;
        if (num % i != 0)
          break;
      }
      p.push_back(i);
    }
    i++;
  }
  if (num != 1)
    p.push_back(num);
  sort(all(p));
  num = p.size();
  vector<bool> pp(num);

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < num; j++) {
      if (pp[j])
        continue;
      if (a[i] % p[j] != 0)
        pp[j] = true;
    }
  }
  rep(i, num) if (!pp[i]) st = false;

  num = 0;
  rep(i, n) if (a[i] == 1) num++;

  if (n - num > 79000)
    pr = false;
  else {
    vector<int> vv(10000000);
    for (int i = 0; i < n; i++) {
      int j = 2;
      while (j * j <= a[i]) {
        if (a[i] % j == 0) {
          while (true) {
            a[i] /= j;
            if (a[i] % j != 0)
              break;
          }
          if (vv[j]) {
            pr = false;
            break;
          }
          vv[j] = true;
        }
        j++;
      }
      if (a[i] != 1) {
        if (vv[a[i]]) {
          pr = false;
          break;
        }
        vv[a[i]] = true;
      }
    }
  }

  if (a[n - 1] == 1)
    pr - true;
  if (pr)
    cout << "pairwise coprime" << endl;
  else if (st)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main() {

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool st = true, pr = true;

  sort(all(a));
  int i = 2;
  int num = a[0];
  vector<int> p;
  while (i * i <= num) {
    if (num % i == 0) {
      while (true) {
        num /= i;
        if (num % i != 0)
          break;
      }
      p.push_back(i);
    }
    i++;
  }
  if (num != 1)
    p.push_back(num);
  sort(all(p));
  num = p.size();
  vector<bool> pp(num);

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < num; j++) {
      if (pp[j])
        continue;
      if (a[i] % p[j] != 0)
        pp[j] = true;
    }
  }
  rep(i, num) if (!pp[i]) st = false;

  if (n > 79000)
    pr = false;
  else {
    vector<int> vv(1000);
    for (int i = 0; i < n; i++) {
      int j = 2;
      while (j * j <= a[i]) {
        if (a[i] % j == 0) {
          while (true) {
            a[i] /= j;
            if (a[i] % j != 0)
              break;
          }
          if (vv[j]) {
            pr = false;
            break;
          }
          vv[j] = true;
        }
        j++;
      }
      if (a[i] != 1) {
        if (vv[a[i]]) {
          pr = false;
          break;
        }
        vv[a[i]] = true;
      }
    }
  }

  if (pr)
    cout << "pairwise coprime" << endl;
  else if (st)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}