alexjercan/bugnet huggingface dataset:
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
unordered_map<int, int> m;

void get_num(int x) {
  for (int i = 2; i <= x / i; i++) {
    if (x % i == 0) {
      m[i]++;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x != 1)
    m[x]++;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin >> n;
  bool pc = true, sc = false;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    get_num(a[i]);
  }
  unordered_map<int, int>::iterator iter;
  for (iter = m.begin(); iter != m.end(); iter++) {
    if (iter->second > 1) {
      pc = false;
      break;
    }
  }
  int ans = gcd(max(a[0], a[1]), min(a[0], a[1]));
  for (int i = 2; i < n; i++) {
    int x = ans;
    int y = a[i];
    if (x < y)
      swap(x, y);
    ans = gcd(x, y);
  }
  if (pc) {
    cout << "pairwise coprime" << endl;
  } else if (!pc && ans == 1) {
    cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;

int gcd(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = 1;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  bool pc = true, sc = false;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (gcd(a[i], a[j]) != 1) {
        pc = false;
        break;
      }
    }
    if (!pc)
      break;
  }
  if (!pc) {
    int tmp = gcd(a[0], a[1]);
    for (int i = 2; i < n; i++) {
      tmp = gcd(tmp, a[i]);
      if (tmp == 1)
        sc = true;
      if (sc)
        break;
    }
  }

  if (pc)
    cout << "pairwise coprime" << endl;
  else if (!pc && sc)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int maxn = 1e6 + 13;

set<int> d[maxn];
int a[maxn];
int p[maxn]; // 筛出每个数最小素因子
int cnt[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  p[1] = 0;
  for (int i = 2; i <= maxn; i++) {
    if (p[i])
      continue;
    for (int j = i; j <= maxn; j += i) {
      p[j] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = a[i]; p[j]; j /= p[j]) {
      d[i].insert(p[j]);
    }
  }
  int type = 0;
  for (int i = 1; i <= n; i++) {
    for (const auto &j : d[i]) {
      if (++cnt[j] >= 2) {
        type = 1;
      }
    }
  }
  int gcd = a[1];
  for (int i = 2; i <= n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  if (gcd != 1) {
    printf("not coprime");
  } else if (gcd == 1) {
    if (type == 1) {
      printf("setwise coprime");
    } else {
      printf("pairwise coprime");
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 1e6 + 7;
int prime[maxn];
int n;
int isprime[maxn];
int a[maxn];
int vis[maxn];
int main() {
  int n;
  scanf("%d", &n);
  int cnt = 0;
  memset(isprime, 1, sizeof(isprime));
  isprime[0] = isprime[1] = 0;
  for (int i = 2; i <= maxn; i++) {
    if (isprime[i])
      prime[++cnt] = i;
    for (int j = 1; j <= cnt && prime[j] * i <= maxn; j++) {
      isprime[prime[j] * i] = 0;
      if (i % prime[j] == 0)
        break;
    }
  }
  int type = 0;
  int gcd;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i == 1)
      gcd = a[i];
    else
      gcd = __gcd(gcd, a[i]);
    if (isprime[a[i]]) {
      int j = a[i];
      vis[j]++;
      if (vis[j] >= 2 && type == 0)
        type = 1;
      continue;
    }
    for (int j = 2; j * j <= a[i]; j++) {
      if (isprime[j] == 0)
        continue;
      if (a[i] % j == 0) {
        vis[j]++;
        if (vis[j] >= 2 && type == 0)
          type = 1;
        int t = a[i] / j;
        if (isprime[t] && t != j) {
          vis[t]++;
          if (vis[t] >= 2 && type == 0)
            type = 1;
        }
      }
    }
  }
  if (gcd != 1)
    type = 2;
  if (type == 2)
    printf("not coprime");
  else if (type == 1)
    printf("setwise coprime");
  else
    printf("pairwise coprime");
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = int(a); i < (int)b; ++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll, ll>>
#define pb push_back

using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const ll mod = 1e9 + 7;
const ll inf = 1e6;

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n), d(inf + 1);
  vector<ll> gcds(inf);
  for (int i = 2; i <= inf; ++i) {
    if (d[i])
      continue;
    d[i] = i;
    ll k = i * 2;
    while (k <= inf) {
      d[k] = i;
      k += i;
    }
  }
  rep(i, n) {
    cin >> a[i];
    ll k = a[i];
    while (k != 1) {
      ++gcds[d[k] - 1];
      ll tmp = d[k];
      while (tmp == d[k]) {
        k /= d[k];
      }
    }
  }
  ll l = 0, s = 1e18;
  rep(i, inf) {
    if (i == 0)
      continue;
    l = max(gcds[i], l);
  }

  if (l == n) {
    cout << "not coprime" << endl;
  } else if (l <= 1) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = int(a); i < (int)b; ++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll, ll>>
#define pb push_back

using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const ll mod = 1e9 + 7;
const ll inf = 1e6;
vector<ll> gcds(inf);

void gcd(ll x) {
  ll k = 1;
  while (k * k <= x) {
    if (k * k == x) {
      ++gcds[k - 1];
    } else if (x % k == 0) {
      ++gcds[k - 1];
      ++gcds[x / k - 1];
    }
    ++k;
  }
}

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    gcd(a[i]);
  }
  ll l = 0, s = 1e18;
  rep(i, inf) {
    if (i == 0)
      continue;
    l = max(gcds[i], l);
    s = min(gcds[i], s);
  }

  if (l == n) {
    cout << "not coprime" << endl;
  } else if (l <= 1) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }

  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pi pair<int, int>
#define pb push_back

// dont forget to initialize global variables inside main() ;
int mod = 1e9 + 7;

vector<int> v(1000001, 1);
void fac(int a, unordered_map<int, int> &m) {
  for (int i = 2; i * i <= a; i++) {
    if (v[a] == 1) {
      break;
    }
    if (a % i == 0) {
      m[i]++;
    }
    while (a % i == 0)
      a = a / i;
  }
  if (a != 1)
    m[a]++;
}

void seive(int n) {

  for (int i = 2; i * i <= n; i++) {
    if (v[i] == 1) {
      for (int j = i * i; j <= n; j = j + i) {
        if (j % i == 0)
          v[j] = 0;
      }
    }
  }
}

int32_t main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int tt = 1; //;cin>>tt;

  seive(1000000);
  v[1] = 0;
  while (tt--) {

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      cin >> a[i];
    unordered_map<int, int> m;
    for (int i = 0; i < n; i++) {
      if (v[a[i]] == 1) {
        m[a[i]]++;
        continue;
      }
      fac(a[i], m);
    }
    int f = 0;
    for (auto i : m) {
      if (i.second > 1) {
        f = 1;
        break;
      }
    }
    if (f == 0) {
      cout << "pairwise coprime" << endl;
      return 0;
    }
    int gcd = a[0];
    for (int i = 1; i < n; i++) {
      gcd = __gcd(gcd, a[i]);
    }
    if (gcd == 1) {
      cout << "setwise coprime" << endl;
      return 0;
    } else
      cout << "not coprime" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pi pair<int, int>
#define pb push_back

// dont forget to initialize global variables inside main() ;
int mod = 1e9 + 7;

vector<int> v(1000001, 1);
void fac(int a, unordered_map<int, int> &m) {
  for (int i = 2; i * i <= a; i++) {
    if (v[a] == 1) {
      m[a]++;
      return;
    }
    if (a % i == 0) {
      m[i]++;
    }
    while (a % i == 0)
      a = a / i;
  }
  if (a != 1)
    m[a]++;
}

void seive(int n) {

  for (int i = 2; i * i <= n; i++) {
    if (v[i] == 1) {
      for (int j = i * i; j <= n; j++) {
        if (j % i == 0)
          v[j] = 0;
      }
    }
  }
}

int32_t main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int tt = 1; //;cin>>tt;

  seive(1000000);
  v[1] = 0;
  while (tt--) {

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      cin >> a[i];
    unordered_map<int, int> m;
    for (int i = 0; i < n; i++) {
      if (v[a[i]] == 1) {
        m[a[i]]++;
        continue;
      }
      fac(a[i], m);
    }
    int f = 0;
    for (auto i : m) {
      if (i.second > 1) {
        f = 1;
        break;
      }
    }
    if (f == 0) {
      cout << "pairwise coprime" << endl;
      return 0;
    }
    int gcd = a[0];
    for (int i = 1; i < n; i++) {
      gcd = __gcd(gcd, a[i]);
    }
    if (gcd == 1) {
      cout << "setwise coprime" << endl;
      return 0;
    } else
      cout << "not coprime" << endl;
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

class Prime {
  vector<bool> is_prime;
  int n;

public:
  Prime(int n) : n(n) {
    is_prime.resize(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
      if (is_prime[i]) {
        for (int j = 2 * i; j <= n; j += i)
          is_prime[j] = false;
      }
    }
  }
  bool operator[](const int &k) const { return is_prime[k]; }
};

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll g = a[0];
  ll m = 1;
  vector<ll> b;
  rep(i, n) {
    g = gcd(g, a[i]);
    m = max(m, a[i]);
    if (a[i] != 1)
      b.push_back(a[i]);
  }
  Prime prime(m);
  ll nb = (ll)b.size();
  int sz = 0;
  for (int i = 2; i <= m; i++)
    if (prime[i])
      sz++;
  if (nb > sz) {
    if (g == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
    return 0;
  }
  bool f = true;
  vector<ll> v(MAX);
  rep(i, nb) {
    for (ll j = 2; j * j <= b[i]; j++) {
      if (b[i] % j == 0)
        v[j]++;
      while (b[i] % j == 0) {
        b[i] /= j;
      }
    }
    if (b[i] > 1)
      v[b[i]]++;
  }
  for (int i = 2; i < MAX; i++)
    if (v[i] >= 2)
      f = false;
  if (f)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

class Prime {
  vector<bool> is_prime;
  int n;

public:
  Prime(int n) : n(n) {
    is_prime.resize(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
      if (is_prime[i]) {
        for (int j = 2 * i; j <= n; j += i)
          is_prime[j] = false;
      }
    }
  }
  bool operator[](const int &k) const { return is_prime[k]; }
};

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll g = a[0];
  ll m = 1;
  vector<ll> b;
  rep(i, n) {
    g = gcd(g, a[i]), m = max(m, a[i]);
    if (a[i] != 1)
      b.push_back(a[i]);
  }
  Prime prime(m);
  n = b.size();
  int sz = 0;
  for (int i = 2; i <= m; i++)
    if (prime[i])
      sz++;
  if (n > sz) {
    if (g == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
    return 0;
  }
  bool f = true;
  for (int i = 2; i <= m; i++) {
    if (prime[i]) {
      int res = 0;
      rep(j, n) {
        if (b[j] % i == 0) {
          res++;
          if (res >= 2)
            break;
        }
      }
      if (res >= 2) {
        f = false;
        break;
      }
    }
  }
  if (f)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int64_t gcd(int64_t a, int64_t b) {
  if (a % b == 0)
    return (b);
  return (gcd(b, a % b));
}

int main(void) {
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t maxA = 0;
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] > maxA)
      maxA = A[i];
  }
  vector<int64_t> D(maxA + 1, -1);
  vector<int64_t> primes;
  for (int64_t i = 2; i <= maxA; ++i) {
    int64_t can_div = i;
    for (auto p : primes) {
      if (p * p > i) {
        break;
      }
      if (i % p == 0) {
        can_div = p;
        break;
      }
    }
    if (can_div == i) {
      primes.push_back(i);
    }
    D[i] = can_div;
  }

  vector<int64_t> seen(maxA + 1, -1);
  for (int i = 0; i < N; ++i) {
    const int64_t ORIGA = i;
    auto a = A[i];

    while (a != 1) {
      int64_t p = D[a];
      if ((seen[p] != -1) && (seen[p] != ORIGA)) {
        int64_t gcd_ret = A[0];
        for (int64_t i = 1; i < N; ++i) {
          gcd_ret = gcd(gcd_ret, A[i]);
        }
        if (gcd_ret == 1) {
          cout << "setwise coprime" << endl;
        } else {
          cout << "not coprime" << endl;
        }
        exit(0);
      }
      seen[p] = ORIGA;
      a /= p;
    }
  }

  cout << "pairwise coprime" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  int maxA = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] > maxA)
      maxA = A[i];
  }
  vector<int> D(maxA + 1);
  vector<int> primes;
  for (int i = 2; i <= maxA; ++i) {
    int can_div = i;
    for (auto p : primes) {
      if (i % p == 0) {
        can_div = p;
        break;
      }
    }
    if (can_div == i) {
      primes.push_back(i);
    }
    D[i] = can_div;
  }

  vector<int> seen(maxA + 1, -1);
  bool will_continue = true;
  for (auto a : A) {
    if (will_continue == false)
      break;

    auto origA = a;
    while (a >= 2) {
      auto p = D[a];
      if (seen[p] != -1 && seen[p] != origA) {
        will_continue = false;
        break;
      }
      seen[p] = origA;
      a /= p;
    }
  }
  if (will_continue) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int gcd_ret = A[0];
  for (int i = 1; i < N; ++i) {
    gcd_ret = gcd(gcd_ret, A[i]);
  }

  if (gcd_ret == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(), c.end()
#define init(c) memset(c, 0, sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N = 20000005;
int n, k, x, t, a, b, m;
string s;
vi v;

void solve() {
  scanf("%d", &n);
  map<int, int> freq;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    v.push_back(x);
    freq[x]++;
  }
  int sq = 1e3 + 10;
  bool pairwise = true;
  bool vis[1000005];
  for (int i = 0; i <= 1e6; i++) {
    vis[i] = false;
  }
  for (int i = 2; i <= 1e6; i++) {
    int cnt = 0;
    if (!vis[i]) {
      for (int j = i; j <= 1e6; j += i) {
        cnt += freq[j];
        vis[j] = true;
      }

      if (cnt > 1) {
        pairwise = false;
        break;
      }
    }
  }
  if (!pairwise) {
    int gd = v[0];
    for (int i = 1; i < n; i++) {
      gd = __gcd(v[i], gd);
    }
    if (gd == 1) {
      printf("setwise coprime");
    } else {
      printf("not coprime");
    }
  } else {
    printf("pairwise coprime");
  }
}

int main() {

  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(), c.end()
#define init(c) memset(c, 0, sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N = 20000005;
int n, k, x, t, a, b, m;
string s;
vi v;

void solve() {
  scanf("%d", &n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    v.push_back(x);
    mp[x]++;
  }
  int sq = 1e3 + 10;
  bool pairwise = true;

  for (int i = 2; i <= sq; i++) {
    int cnt = 0;
    for (int j = i; j <= 1e6; j += i) {
      cnt += mp[j];
    }
    if (cnt > 1) {
      pairwise = false;
    }
  }
  if (!pairwise) {
    int gd = v[0];
    for (int i = 1; i < n; i++) {
      gd = __gcd(v[i], gd);
    }
    if (gd == 1) {
      printf("setwise coprime");
    } else {
      printf("not coprime");
    }
  } else {
    printf("pairwise coprime");
  }
}

int main() {

  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n, a[1000010], x;
bool p[1000010], f[1000010], k;
vector<int> prime;
int main() {
  p[0] = p[1] = 1;
  for (int i = 2; i <= 1000; i++)
    if (p[i] == 0)
      for (int j = i + i; j <= 1000; j += i)
        p[j] = 1;
  for (int i = 0; i <= 1000; i++)
    if (p[i] == 0)
      prime.push_back(i);
  cin >> n;
  for (int i = 0; i < 1000010; i++)
    a[i] = 1e9;
  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int j = 0; j < prime.size(); j++) {
      int num = 0;
      while ((x % prime[j]) == 0) {
        num++;
        x /= prime[j];
      }
      a[j] = min(a[j], num);
      if (f[j] == 1 && num > 0)
        k = 1;
      if (num > 0)
        f[j] = 1;
    }
    if (x != 1)
      if (f[x] == 1)
        k = 1;
    if (x != 1)
      f[x] = 1;
  }
  if (k == 0)
    cout << "pairwise coprime" << endl;
  else {
    k = 0;
    for (int i = 0; i <= 1000; i++)
      if (a[i] == 0 || a[i] == 1000000000)
        continue;
      else
        k = 1;
    if (k == 1)
      cout << "not coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, a[1000010], x;
bool p[1000010], f[1000010], k;
vector<int> prime;
int main() {
  p[0] = p[1] = 1;
  for (int i = 2; i <= 1000000; i++)
    if (p[i] == 0)
      for (int j = i + i; j <= 1000000; j += i)
        p[j] = 1;
  for (int i = 0; i <= 1000000; i++)
    if (p[i] == 0)
      prime.push_back(i);
  cin >> n;
  for (int i = 0; i < 1000010; i++)
    a[i] = 1e9;
  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int j = 0; j < prime.size(); j++) {
      int num = 0;
      while ((x % prime[j]) == 0) {
        num++;
        x /= prime[j];
      }
      a[j] = min(a[j], num);
      if (f[j] == 1 && num > 0)
        k = 1;
      if (num > 0)
        f[j] = 1;
    }
  }
  if (k == 0)
    cout << "pairwise coprime" << endl;
  else {
    k = 0;
    for (int i = 0; i <= 1000000; i++)
      if (a[i] == 0 || a[i] == 1000000000)
        continue;
      else
        k = 1;
    if (k == 1)
      cout << "not coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

#define NUM 1000001

int prime[NUM];
bool factor[NUM];

void seive() {

  for (int i = 0; i < NUM; i++) {
    prime[i] = -1;
    factor[i] = false;
  }

  for (int i = 2; i * i <= NUM; i++) {
    if (prime[i] == -1) {
      for (int j = i * 2; j < NUM; j += i) {
        if (prime[j] == -1) {
          prime[j] = i;
        }
      }
    }
  }
}
bool prime_factors(int n) {

  if (n == 1)
    return true;

  set<int> temp;
  while (prime[n] != -1) {
    temp.insert(prime[n]);
    n /= prime[n];
  }
  temp.insert(n);
  for (auto itr = temp.begin(); itr != temp.end(); itr++) {
    if (!factor[*itr]) {
      factor[*itr] = true;
    } else {
      return false;
    }
  }
  return true;
}

int main() {

  seive();

  int n;
  cin >> n;

  int temp;

  int gcd = 0;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    gcd = __gcd(temp, gcd);
    if (flag) {
      flag = prime_factors(temp);
    }
  }

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

  return 0;
}


Error: WA

Fixed submission:

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

#define NUM 1000001

int prime[NUM];
bool factor[NUM];

void seive() {

  for (int i = 0; i < NUM; i++) {
    prime[i] = -1;
    factor[i] = false;
  }

  for (int i = 2; i * i <= NUM; i++) {
    if (prime[i] == -1) {
      for (int j = i * 2; j < NUM; j += i) {
        if (prime[j] == -1) {
          prime[j] = i;
        }
      }
    }
  }
}

bool prime_factors(int n) {
  while (prime[n] != -1) {
    // cout<<prime[n]<<" ";
    if (!factor[prime[n]]) {
      factor[prime[n]] = true;
    } else {
      return false;
    }
    n /= prime[n];
  }
  // cout<<n<<endl;
  // return true;
  if (!factor[prime[n]]) {
    factor[prime[n]] = true;
  } else {
    return false;
  }
}

int main() {

  seive();

  int n;
  cin >> n;

  int temp;
  bool flag = true;
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    gcd = __gcd(temp, gcd);
    if (flag) {
      flag = prime_factors(temp);
    }
  }

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

  return 0;
}