alexjercan/bugnet huggingface dataset:
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int gcd(ll a, ll b) {
  if (min(a, b) == 0)
    return max(a, b);
  return gcd(min(a, b), max(a, b) % min(a, b));
}

vector<bool> sosu(1000010, 0);

bool gcdc(ll n) {
  queue<ll> q;
  for (int i = 2; i * i <= n; i++) {
    if (n % i) {
      continue;
    }
    bool check = 0;
    while (n % i == 0) {
      check = 1;
      n /= i;
    }
    q.push(i);
  }
  if (n != 1) {
    q.push(n);
  }
  while (q.size() > 0) {
    if (sosu.at((q.front()))) {
      return 0;
    }
    sosu.at(q.front()) = 1;
    q.pop();
  }
  return 1;
}

using namespace std;
using ll = long long;

int main() {
  ll N = 0;
  cin >> N;
  int each = 0;
  int all = 1;
  vector<ll> A(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    ll memo = gcd(A.at(i), A.at(i + 1));
    if (memo == 1) {
      each = 1;
      break;
    } else {
      A.at(i + 1) = memo;
    }
  }

  for (int i = 0; i < N; i++) {
    if (!gcdc(A.at(i))) {
      all = 0;
      break;
    }
  }

  if (all) {
    cout << "pairwise coprime" << endl;
  } else if (each) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int gcd(ll a, ll b) {
  if (min(a, b) == 0)
    return max(a, b);
  return gcd(min(a, b), max(a, b) % min(a, b));
}

vector<bool> sosu(1010);

bool gcdc(ll n) {
  queue<ll> q;
  for (int i = 2; i <= n; i++) {
    if (n % i) {
      continue;
    }
    bool check = 0;
    while (n % i == 0) {
      check = 1;
      n /= i;
    }
    q.push(i);
  }
  while (q.size()) {
    if (sosu.at((q.front()))) {
      return 0;
    }
    sosu.at(q.front()) = 1;
    q.pop();
  }
  return 1;
}

using namespace std;
using ll = long long;

int main() {
  ll N = 0;
  cin >> N;
  int each = 0;
  int all = 1;
  vector<ll> A(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    ll memo = gcd(A.at(i), A.at(i + 1));
    if (memo == 1) {
      each = 1;
      break;
    } else {
      A.at(i + 1) = memo;
    }
  }

  for (int i = 0; i < N; i++) {
    if (!gcdc(A.at(i))) {
      all = 0;
      break;
    }
  }

  if (all) {
    cout << "pairwise coprime" << endl;
  } else if (each) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

vector<int> hurui(int n) {
  vector<int> d(n + 1, -1);
  d[1] = 1;
  int curr_d;
  for (int i = 2; i <= n; i++) {
    if (d[i] == -1) {
      curr_d = i;
      for (int j = 1; j < n / curr_d + 1; j++) {
        if (d[curr_d * j] == -1) {
          d[curr_d * j] = curr_d;
        }
      }
    }
  }
  return d;
}

bool gozyohou1(vector<int> a) {
  sort(a.begin(), a.end());
  vector<int> d = hurui(a.at((int)a.size() - 1));
  set<int> primes;
  int p;
  int dp;
  for (int i = 0; i < (int)a.size(); i++) {
    p = a.at(i);
    while (d[p] != p) {
      if (primes.count(d[p])) {
        return false;
      }
      primes.insert(d[p]);
      dp = d[p];
      while (p % dp == 0) {
        p /= dp;
      }
    }
    if (primes.count(d[p])) {
      return false;
    }
    if (p != 1) {
      primes.insert(d[p]);
    }
  }
  return true;
}
bool gozyohou2(vector<int> a) {
  sort(a.begin(), a.end());
  while (a.at(0) > 1) {
    for (int i = 1; i < (int)a.size(); i++) {
      a.at(i) %= a.at(0);
    }
    a.erase(remove_if(a.begin(), a.end(), [](int x) { return x == 0; }),
            a.end());
    if ((int)a.size() == 1) {
      return false;
    }
    sort(a.begin(), a.end());
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  if (gozyohou1(a)) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  if (gozyohou2(a)) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}


Error: 0

Fixed submission:

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

vector<int> hurui(int n) {
  vector<int> d(n + 1, -1);
  int curr_d;
  for (int i = 2; i <= n; i++) {
    if (d[i] == -1) {
      curr_d = i;
      for (int j = 1; j < n / curr_d + 1; j++) {
        if (d[curr_d * j] == -1) {
          d[curr_d * j] = curr_d;
        }
      }
    }
  }
  return d;
}

bool gozyohou1(vector<int> a) {
  sort(a.begin(), a.end());
  vector<int> d = hurui(a.at((int)a.size() - 1));
  set<int> primes;
  int p;
  for (int i = 0; i < (int)a.size(); i++) {
    p = a.at(i);
    while (d[p] != p) {
      if (primes.count(d[p])) {
        return false;
      }
      primes.insert(d[p]);
      p /= d[p];
    }
  }
  return true;
}
bool gozyohou2(vector<int> a) {
  sort(a.begin(), a.end());
  while (a.at(0) > 1) {
    for (int i = 1; i < (int)a.size(); i++) {
      a.at(i) %= a.at(0);
    }
    a.erase(remove_if(a.begin(), a.end(), [](int x) { return x == 0; }),
            a.end());
    if ((int)a.size() == 1) {
      return false;
    }
    sort(a.begin(), a.end());
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  if (gozyohou1(a)) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  if (gozyohou2(a)) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  // sengen
  int n;
  // nyuryoku
  cin >> n;
  int a[n];
  int b[1000001] = {};
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  int c = 1;
  // keisan
  int ans = 1;
  for (int i = 2; i <= 1000000; i++) {
    int tmp = 0;
    for (int j = 1; i * j <= 1000000; j++) {
      tmp += b[i * j];
    }
    if (tmp > 1) {
      c = 0;
    }
    ans = max(ans, tmp);
  }
  if (c) {
    cout << "pairwise coprime" << endl;
  } else if (ans == n) {
    cout << "not coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }
  // syutsuryoku
}

Error: TLE

Fixed submission:

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

int sosu(int n) {
  if (n == 2)
    return 1;
  else if (n % 2 == 0)
    return 0;

  double a = sqrt(n);
  for (int i = 3; i <= a; i += 2) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}

int main() {
  // sengen
  int n;
  // nyuryoku
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  // keisan
  int cmax = 0, tmp = 0;
  int i = 2;
  while (i <= a[n - 1]) {
    tmp = 0;
    if (sosu(i)) {
      for (int j = 0; j < n; j++) {
        if (a[j] % i == 0) {
          tmp++;
        }
      }
      cmax = max(cmax, tmp);
    }
    if (i == 2) {
      i++;
    } else {
      i += 2;
    }
  }
  if (cmax < 2) {
    cout << "pairwise coprime" << endl;
  } else if (cmax < n) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  // syutsuryoku
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int, int>
#define se second
#define fi first
using namespace std;
const int d[] = {2, 3, 5, 7};
int n, a[1000005];
int gcd(int a, int b) {
  if (!b)
    re a;
  else
    re gcd(b, a % b);
}
bool set_coprime = 0, pair_coprime = 1;
int cnt[1000005];
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int res = a[0];
  for (int i = 1; i < n; i++)
    res = gcd(res, a[i]);
  if (res == 1)
    set_coprime = 1;
  bool should_break = 0;
  for (int i = 0; i < n; i++) {
    vector<int> v;
    v.pb(a[i]);
    for (int j = 0; j < 4; j++) {
      if (a[i] % d[j] == 0) {
        v.pb(d[j]);
        v.pb(a[i] / d[j]);
      }
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    for (int i = 0; i < sz(v); i++) {
      // cout<<v[i]<<"\\n";
      if (v[i] == 1)
        continue;
      cnt[v[i]]++;
      if (cnt[v[i]] > 1) {
        pair_coprime = 0;
        should_break = 1;
        break;
      }
    }
    if (should_break)
      break;
  }
  if (pair_coprime)
    cout << "pairwise coprime";
  else
    cout << (set_coprime ? "setwise coprime" : "not coprime");
  re 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int, int>
#define se second
#define fi first
using namespace std;
int n, a[1000005];
int gcd(int a, int b) {
  if (!b)
    re a;
  else
    re gcd(b, a % b);
}
bool set_coprime = 0, pair_coprime = 1;
int cnt[1000005];
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int res = a[0];
  for (int i = 1; i < n; i++)
    res = gcd(res, a[i]);
  if (res == 1)
    set_coprime = 1;
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        cnt[j]++, cnt[a[i] / j]++;
        if (j * j == a[i])
          cnt[j]--;
      }
    }
  }
  for (int i = 2; i <= 1e6; i++) {
    if (cnt[i] > 1) {
      pair_coprime = 0;
      break;
    }
  }
  if (pair_coprime)
    cout << "pairwise coprime";
  else
    cout << (set_coprime ? "setwise coprime" : "not coprime");
  re 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int vet[1001000], dividers[1001000];

bool div(int x) {
  if (x == 1)
    return false;

  if (dividers[x]++) {
    return true;
  }

  int i = 2;
  while (i * i < x) {
    if (x % i == 0) {
      if (dividers[i]++)
        return true;

      if (dividers[x / i]++)
        return true;
    }
    i++;
  }

  if (x % i == 0 && x != i) {
    if (dividers[i]++) {
      return true;
    }
  }

  return false;
}

int gcd(int a, int b) {
  while (a) {
    int aux = a;
    a = b % a;
    b = aux;
  }

  return b;
}

int main() {
  int n, g;

  scanf(" %d", &n);

  scanf(" %d", vet);
  g = vet[0];

  for (int i = 1; i < n; i++)
    scanf(" %d", vet + i), g = gcd(g, vet[i]);

  if (g != 1) {
    printf("not coprime\\n");
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (div(vet[i])) {
      printf("setwise coprime\\n");
      return 0;
    }
  }

  printf("pairwise coprime\\n");

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int vet[100100], dividers[100100];

void div(int x) {
  int i;
  for (i = 2; i * i < x; i++)
    if (x % i == 0) {
      dividers[i]++;
      dividers[x / i]++;
    }

  if (x % i == 0)
    dividers[i]++;
}

int gcd(int a, int b) {
  while (a) {
    int aux = a;
    a = b % a;
    b = aux;
  }

  return b;
}

int main() {
  int n, g;

  scanf(" %d", &n);

  scanf(" %d", vet);
  g = vet[0];
  div(g);

  for (int i = 1; i < n; i++)
    scanf(" %d", vet + i), g = gcd(vet[i], g), div(vet[i]);

  if (g != 1) {
    printf("not coprime\\n");
    return 0;
  }

  for (int i = 2; i <= 100; i++) {
    if (dividers[i] > 1) {
      printf("setwise coprime\\n");
      return 0;
    }
  }

  printf("pairwise coprime\\n");

  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  int a[n];
  bool flag = true;
  map<int, int> mp;
  for (int j = 0; j < n; ++j) {
    cin >> a[j];

    if (flag) {
      for (long long int i = 1; i * i <= a[j]; ++i) {
        if (a[j] % i == 0) {
          mp[i]++;
          if (i != 1 && mp[i] >= 2) {
            flag = false;
          }
          if (i != 1 && i * i != a[j]) {
            mp[a[j] / i]++;
            if (a[j] / i != 1 && mp[a[j] / i] >= 2) {
              flag = false;
            }
          }
        }
      }
      mp[a[j]]++;
      if (a[j] != 1 && mp[a[j]] >= 2) {
        flag = false;
      }
    }
  }

  int gcd = __gcd(a[0], a[1]);
  for (int i = 2; i < n; ++i) {
    gcd = __gcd(gcd, a[i]);
  }

  if (gcd == 1) {
    if (!flag) {
      cout << "setwise coprime" << '\\n';
    } else {
      cout << "pairwise coprime" << '\\n';
    }
  } else {
    cout << "not coprime" << '\\n';
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int a[n];
  bool flag = true;
  map<int, int> mp;
  for (int j = 0; j < n; ++j) {
    cin >> a[j];

    if (flag) {
      for (long long int i = 1; i * i <= a[j]; ++i) {
        if (a[j] % i == 0) {
          mp[i]++;
          if (i != 1 && mp[i] >= 2) {
            flag = false;
            break;
          }
          if (i != 1 && i * i != a[j]) {
            mp[a[j] / i]++;
            if (a[j] / i != 1 && mp[a[j] / i] >= 2) {
              flag = false;
              break;
            }
          }
        }
      }
      mp[a[j]]++;
      if (a[j] != 1 && mp[a[j]] >= 2) {
        flag = false;
        break;
      }
    }
  }

  int gcd = __gcd(a[0], a[1]);
  for (int i = 2; i < n; ++i) {
    gcd = __gcd(gcd, a[i]);
  }

  if (gcd == 1) {
    if (!flag) {
      cout << "setwise coprime" << '\\n';
    } else {
      cout << "pairwise coprime" << '\\n';
    }
  } else {
    cout << "not coprime" << '\\n';
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> key;
  ll res = 1;
  rep(k, n) {
    ll tmp = a[k];
    for (int i = 2; i * i <= tmp; i++) {

      if (tmp % i == 0 && 0 < key[i])
        res = 0;
      while (tmp % i == 0) {
        tmp /= i;
        key[i] = 1;
      }
    }
    if (1 < tmp) {
      if (0 < key[tmp])
        res = 0;
      key[tmp] = 1;
    }
    if (res == 0)
      break;
  }
  if (res == 1)
    cout << "pairwise coprime";
  else {
    res = a[0];
    rep(i, n - 1) {
      res = gcd(res, a[i + 1]);
      // cout << res << ' ';
    }
    if (res == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> key;
  ll res = 1;
  sort(ALL(a));
  rep(k, n) {
    ll tmp = a[k];
    for (int i = 2; i * i <= tmp; i++) {
      if (tmp % i == 0 && 0 < key[i])
        res = 0;
      if (tmp % i == 0)
        key[i] += 1;
      while (tmp % i == 0) {
        tmp /= i;
      }
    }
    if (1 < tmp) {
      if (0 < key[tmp])
        res = 0;
      key[tmp] += 1;
    }
  }
  if (res == 1)
    cout << "pairwise coprime";
  else {
    res = 1;
    for (auto x : key) {
      if (x.second == n) {
        res = 0;
        break;
      }
    }
    if (res == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  }
  cout << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(a, n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef vector<vector<ll>> Graph;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e18;

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll g = 0;
  rep(i, n) {
    cin >> a[i];
    g = __gcd(a[i], g);
  }
  vector<ll> cnt(1e6 + 1);
  rep(i, n) {
    auto res = prime_factorize(a[i]);
    rep(j, res.size()) {
      ll div = res[j].first;
      cnt[div]++;
    }
  }
  bool fi = true;
  rep(i, 1e6 + 1) {
    if (cnt[i] > 1) {
      fi = false;
      break;
    }
  }
  if (fi) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(a, n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef vector<vector<ll>> Graph;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e18;

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> mp;
  rep(i, n) {
    auto res = prime_factorize(a[i]);
    rep(j, res.size()) {
      ll div = res[j].first;
      mp[div]++;
    }
  }
  bool fi = true;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second > 1) {
      fi = false;
      break;
    }
  }
  if (fi) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll g = a[0];
  rep(i, n) { g = __gcd(g, a[i]); }
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) scanf("%d", &a[i]);
  vector<int> cnt(1000005);
  vector<int> m(1000005);
  rep(i, n) m[a[i]]++;
  bool flag = true;
  for (int i = 2; i <= 1000000; i++) {
    int t = 0;
    if (cnt[i] != 0)
      continue;
    for (int j = i; j <= 1000000; j += i) {
      t += m[j];
      cnt[j]++;
    }
    if (t >= 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  rep(i, n) g = __gcd(g, a[i]);
  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) scanf("%d", a[i]);
  vector<int> cnt(1000005);
  vector<int> m(1000005);
  rep(i, n) m[a[i]]++;
  bool flag = true;
  for (int i = 2; i <= 1000000; i++) {
    int t = 0;
    if (cnt[i] != 0)
      continue;
    for (int j = i; j <= 1000000; j += i) {
      t += m[j];
      cnt[j]++;
    }
    if (t >= 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  rep(i, n) g = __gcd(g, a[i]);
  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define For(i, n) for (int i = 0; i < (int)n; ++i)
#define Rep(i, n) for (int i = 1; i <= (int)n; ++i)
#define ll long long
#define lld long double
#define F first
#define S second
#define pb push_back
#define endl "\\n"
#define ar array
#define INF 1e18;
#define all(v) (v).begin(), (v).end()
const int N = 1e6 + 1;
int cnt[N];

bool go(int x) {
  // cnt[x]=1;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      if (cnt[i] == 1 || cnt[x / i] == 1) {
        return false;
      }
      cnt[i] = 1;
      cnt[x / i] = 1;
    }
  }
  return true;
}

void solve() {
  int n, a[N];
  cin >> n;
  memset(cnt, 0, sizeof(cnt));
  For(i, n) cin >> a[i], cnt[a[i]]++;
  sort(a, a + n);
  int val = 0;
  for (int i = 0; i < n; i++) {
    val = __gcd(val, a[i]);
  }
  if (val > 1) {
    cout << "not coprime";
    return;
  }
  For(i, n) {
    if ((cnt[a[i]] > 1 && a[i] != 1) || !go(a[i])) {
      cout << "setwise coprime";
      return;
    }
  }
  cout << "pairwise coprime";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    // cout<<"Case #"<<a<<": ";
    solve();
    // a+=1;
  }
}


Error: WA

Fixed submission:

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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define For(i, n) for (int i = 0; i < (int)n; ++i)
#define Rep(i, n) for (int i = 1; i <= (int)n; ++i)
#define ll long long
#define lld long double
#define F first
#define S second
#define pb push_back
#define endl "\\n"
#define ar array
#define INF 1e18;
#define all(v) (v).begin(), (v).end()
const int N = 1e5 + 1;
int cnt[N];

bool go(int x) {
  cnt[x] = 1;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      if (cnt[i] == 1 || cnt[x / i] == 1) {
        return false;
      }
      cnt[i] = 1;
      cnt[x / i] = 1;
    }
  }
  return true;
}

void solve() {
  int n, a[N];
  cin >> n;
  memset(cnt, 0, sizeof(cnt));
  For(i, n) cin >> a[i];
  sort(a, a + n);
  int val = a[0];
  for (int i = 1; i < n; i++) {
    val = __gcd(val, a[i]);
  }
  if (val > 1) {
    cout << "not coprime";
    return;
  }
  For(i, n) {
    if (cnt[a[i]] == 1 || !go(a[i])) {
      cout << "setwise coprime";
      return;
    }
  }
  cout << "pairwise coprime";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    // cout<<"Case #"<<a<<": ";
    solve();
    // a+=1;
  }
}