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

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

// const int N = 1e9+7;
const int N = 1e6 + 5;
ll parent[N];
ll siz[N];
void make() {
  for (ll i = 0; i < N; i++) {
    parent[i] = i;
    siz[i] = 1;
  }
}
int find(int x) {
  while (parent[x] != x) {
    x = parent[x];
  }
  return x;
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (siz[a] < siz[b]) {
      swap(a, b);
    }
    parent[b] = a;
    // if (siz[a] == siz[b]) {
    siz[a] += siz[b];
    // }
  }
}

bool sieve[N];

void solve() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  map<ll, ll> m;
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
    m[v[i]]++;
  }
  sort(v.begin(), v.end());
  ll gc = v[0];
  for (ll i = 1; i < n; i++) {
    gc = __gcd(v[i], gc);
  }
  if (gc > 1) {
    cout << "not coprime\\n";
    return;
  }
  vector<ll> primes;
  for (ll i = 2; i < (ll)sqrt(N) + 1; i++) {
    if (sieve[i])
      continue;
    for (ll j = i + i; j < N; j += i) {
      sieve[j] = true;
    }
  }
  for (ll i = 2; i < N; i++) {
    if (sieve[i])
      continue;
    primes.push_back(i);
  }
  for (auto y : primes) {
    ll cnt = 0;
    for (ll j = y; j < N; j += y) {
      cnt += m[j];
    }
    if (cnt > 1) {
      cout << "setwise coprime\\n";
      return;
    }
  }
  cout << "pairwise coprime";
}

int main() {
  // freopen("input.txt", "r",stdin);
  // freopen("output.txt", "w", stdout);
  ll t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}

/*
  1 2 3 4 5 6 7 8

  6 7 8 1 2 3 4 5


*/


Error: TLE

Fixed submission:

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

// const int N = 1e9+7;
const int N = 1e6 + 5;
ll parent[N];
ll siz[N];
void make() {
  for (ll i = 0; i < N; i++) {
    parent[i] = i;
    siz[i] = 1;
  }
}
int find(int x) {
  while (parent[x] != x) {
    x = parent[x];
  }
  return x;
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (siz[a] < siz[b]) {
      swap(a, b);
    }
    parent[b] = a;
    // if (siz[a] == siz[b]) {
    siz[a] += siz[b];
    // }
  }
}

bool sieve[N];

void solve() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
  }
  ll gc = v[0];
  for (ll i = 1; i < n; i++) {
    gc = __gcd(v[i], gc);
  }
  if (gc > 1) {
    cout << "not coprime\\n";
    return;
  }
  vector<ll> primes;
  for (ll i = 2; i < (ll)sqrt(N) + 1; i++) {
    if (sieve[i])
      continue;
    for (ll j = i + i; j < N; j += i) {
      sieve[j] = true;
    }
  }
  for (ll i = 2; i < N; i++) {
    if (sieve[i])
      continue;
    primes.push_back(i);
  }
  for (auto y : primes) {
    ll cnt = 0;
    for (auto z : v) {
      if (z % y == 0) {
        cnt++;
      }
    }
    if (cnt > 1) {
      cout << "setwise coprime\\n";
      return;
    }
  }
  cout << "pairwise coprime";
}

int main() {
  // freopen("input.txt", "r",stdin);
  // freopen("output.txt", "w", stdout);
  ll t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}

/*
  1 2 3 4 5 6 7 8

  6 7 8 1 2 3 4 5


*/
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<int> get_prime(int n) {
  vector<int> ans(n + 1, 0);
  for (int i = 2; i < n + 1; i++) {
    if (ans[i] == 0) {
      ans[i] = i;
      if (i * i < n) {
        for (int j = i; j <= n / i; j++) {
          ans[i * j] = i;
        }
      }
    }
  }
  return ans;
}

int gcd(int p, int q) {
  if (p % q == 0) {
    return q;
  } else {
    return gcd(q, p % q);
  }
}

int main() {
  int n, g, a, p;
  cin >> n;
  vector<int> pl = get_prime(1000000);
  int l = pl.size();
  vector<bool> done(l, false);
  bool if_pc = true;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i == 0) {
      g = a;
    } else {
      g = gcd(g, a);
    }
    if (if_pc) {
      while (a != 1) {
        if (done[pl[a]]) {
          if_pc = false;
          break;
        } else {
          p = pl[a];
          while (a % p == 0) {
            a /= p;
          }
          done[p] = true;
        }
      }
    }
  }
  if (if_pc) {
    cout << "pairwise coprime" << endl;
  } else if (g == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

vector<int> get_prime(int n) {
  vector<bool> done(n + 1, false);
  vector<int> ans;
  for (int i = 2; i < n + 1; i++) {
    if (!done[i]) {
      ans.push_back(i);
      if (i * i < n) {
        for (int j = i; j <= n / i; j++) {
          done[i * j] = true;
        }
      }
    }
  }
  return ans;
}

int gcd(int p, int q) {
  if (p % q == 0) {
    return q;
  } else {
    return gcd(q, p % q);
  }
}

int main() {
  int n, g, a;
  cin >> n;
  vector<int> pl = get_prime(1000000);
  int l = pl.size();
  vector<bool> done(l, false);
  bool if_pc = true;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i == 0) {
      g = a;
    } else {
      g = gcd(g, a);
    }
    if (if_pc) {
      for (int j = 0; j < l; j++) {
        if (a % pl[j] == 0) {
          while (a % pl[j] == 0 && a > 1) {
            a /= pl[j];
          }
          if (done[j]) {
            if_pc = false;
          } else {
            done[j] = true;
          }
          // cout << "p " << pl[j] << " a " << a << endl;
        }
        if (a == 1) {
          break;
        }
      }
    }
    // for (int j = 0; j < 10; j++) {
    //     cout << done[j] << " ";
    // }
    // cout << endl;
  }
  if (if_pc) {
    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 <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mes(a, b) memset((a), (b), sizeof((a)))
#define syio                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout.tie(0);
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
typedef long double real;
typedef pair<int, int> pii;

const int oo = ~0u >> 2;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 1000003;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c))
    f = c == '-' ? -1 : 1, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int n, a[mxn], cnt[mxn];
int main() {
  syio;
  cin >> n;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    mx = max(mx, a[i]);
  }
  int f1 = 0, f2 = 0;
  for (int i = 2; i <= mx; ++i) {
    int num = 0;
    for (int j = 1; i * j <= mx; ++j) {
      num += cnt[i * j];
    }
    if (num > 1) {
      f1 = 1;
      break;
    }
  }
  int gd = 0;
  for (int i = 1; i <= n; ++i)
    gd = __gcd(gd, a[i]);
  if (gd == 1)
    f2 = 1;
  if (!f1)
    cout << "pairwise coprime" << endl;
  else if (f2)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mes(a, b) memset((a), (b), sizeof((a)))
#define syio                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout.tie(0);
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
typedef long double real;
typedef pair<int, int> pii;

const int oo = ~0u >> 2;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 1000003;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c))
    f = c == '-' ? -1 : 1, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int n, a[mxn];
map<int, int> ct;
int main() {
  syio;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int f1 = 0, f2 = 0;
  int gd = a[1];
  for (int i = 2; i <= n; ++i)
    gd = __gcd(gd, a[i]);
  if (gd == 1)
    f2 = 1;
  for (int i = 1; i <= n && !f1; ++i) {
    int x = a[i];
    for (int j = 2; j * j <= x; ++j) {
      if (x % j == 0) {
        ct[j]++;
        while (x % j == 0)
          x /= j;
      }
      if (ct[j] >= 2) {
        f1 = 1;
        break;
      }
    }
    if (x != 1)
      ct[x]++;
    if (ct[x] >= 2) {
      f1 = 1;
      break;
    }
  }
  if (!f1)
    cout << "pairwise coprime" << endl;
  else if (f2)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;

ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

// #######################################

int main() {
  boost;
  ll n;
  cin >> n;
  ll a[n];
  ll mx = 0;
  ll count[1000006] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    count[a[i]]++;
    mx = max(mx, a[i]);
  }

  bool flag = true;

  ll counter = 0;

  for (ll i = mx; i > 1; i--) {
    ll j = i;
    counter = 0;

    while (j <= mx) {
      if (count[j] >= 2) {
        flag = false;
        break;
      } else if (count[j] == 1) {
        counter++;
      }

      j += i;

      if (counter == 2) {
        flag = false;
        break;
      }
    }

    if (!flag)
      break;
  }

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

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


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;

ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

// #######################################

int main() {
  boost;
  ll n;
  cin >> n;
  ll a[n];
  ll count[1000006] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (ll j = 1; j <= sqrt(a[i]); j++) {
      if (a[i] % j == 0) {
        count[j]++;
        if (j != a[i] / j) {
          count[a[i] / j]++;
        }
      }
    }
  }
  bool flag = true;
  for (ll i = 2; i < 1000001; i++) {
    if (count[i] > 1) {
      flag = false;
      break;
    }
  }
  ll check1 = a[0];
  for (int i = 1; i < n; i++) {
    check1 = __gcd(check1, a[i]);
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
typedef pair<int, int> pp;
bool com(pp x, pp y) { return x.ff < y.ff; }
int N = 1e6 + 9;
vector<int> dp(N, N);
void solve() {
  dp[1] = 1;
  for (int i = 2; i < N; i++) {
    if (dp[i] < i)
      continue;
    for (int j = i; j < N; j += i)
      dp[j] = min(dp[j], i);
  }
}
int main() {
  // your code goes here
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  int n;
  cin >> n;
  int a[n];
  int gcd, flag = 1;
  map<int, int> mp1, mp2;
  for (int i = 0; i < n; i++)
    cin >> a[i], mp1[a[i]]++;
  gcd = __gcd(a[0], a[1]);
  for (int i = 2; i < n; i++)
    gcd = __gcd(a[i], gcd);
  for (int i = 0; i < n; i++) {
    int k = a[i];
    if (mp1[k] > 1 && k != 1)
      flag = 0;
    // bitset<1000007> vis;
    while (k > 1) {
      if (mp2[dp[k]])
        flag = 0;
      mp2[dp[k]]++;
      int x = dp[k];
      // cout<<dp[k]<<"\\n";
      k /= x;
      while (k % x == 0 && k > 1)
        k /= x;
    }
    if (!flag)
      break;
  }
  if (flag)
    cout << "pairwise coprime";
  else if (gcd == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
typedef pair<int, int> pp;
bool com(pp x, pp y) { return x.ff < y.ff; }
int N = 1e6 + 9;
vector<int> dp(N, N);
void solve() {
  dp[1] = 1;
  for (int i = 2; i < N; i++) {
    if (dp[i] < i)
      continue;
    for (int j = i; j < N; j += i)
      dp[j] = min(dp[j], i);
  }
}
int main() {
  // your code goes here
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  int n;
  cin >> n;
  int a[n];
  int gcd, flag = 1;
  map<int, int> mp1, mp2;
  for (int i = 0; i < n; i++)
    cin >> a[i], mp1[a[i]]++;
  gcd = __gcd(a[0], a[1]);
  for (int i = 0; i < n; i++) {
    int k = a[i];
    gcd = __gcd(a[i], gcd);
    if (mp1[k] > 1 && k != 1)
      flag = 0;
    // bitset<1000007> vis;
    while (k > 1) {
      if (mp2[dp[k]])
        flag = 0;
      mp2[dp[k]]++;
      int x = dp[k];
      // cout<<dp[k]<<"\\n";
      k /= x;
      while (k % x == 0 && k > 1)
        k /= x;
    }
    // if(!flag) break;
  }
  if (flag)
    cout << "pairwise coprime";
  else if (gcd == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int g = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    g = gcd(g, A[i]);
  }
  if (g != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<bool> sosuu(1000008, false);
  sosuu[0] = sosuu[1] = true;
  vector<bool> exa(1000008, false);
  for (int i = 0; i < N; i++) {
    if (A[i] != 1 && exa[A[i]]) {
      cout << "setwise coprime" << endl;
      return 0;
    }
    exa[A[i]] = true;
  }
  for (int i = 0; i < 1000008; i++) {
    if (!sosuu[i]) {
      sosuu[i] = true;
      int kj = 0;
      for (int j = 1; j * i < 1000008; j++) {
        sosuu[i * j] = true;
        if (exa[i * j])
          kj++;
      }
      if (kj > 1) {
        cout << "setwise coprime" << endl;
        return 0;
      }
    }
  }
  cout << "pairwise coprime" << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int g = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    g = gcd(g, A[i]);
  }
  if (g != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<bool> sosuu(1000008, false);
  vector<int> key;
  sosuu[0] = sosuu[1] = true;
  for (int i = 0; i < 1000008; i++) {
    if (!sosuu[i]) {
      sosuu[i] = true;
      key.push_back(i);
      for (int j = 2; j * i < 1000008; j++) {
        sosuu[i * j] = true;
      }
    }
  }
  int n = (int)key.size();
  for (int i = 0; i < n; i++) {
    int kj = 0;
    int k = key[i];
    for (int j = 0; j < N; j++) {
      if (A[j] % k == 0)
        kj++;
    }
    if (kj > 1) {
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "pairwise coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MAXN = 1000000;
int A[MAXN + 5];
int G[MAXN + 5];

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

int main() {
  int n, x;
  int ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    ++A[x];
    ans = gcd(ans, x);
  }
  int ok = 1;
  for (int i = 2; i <= MAXN; ++i) {
    int cnt = 0;
    for (int j = i; j <= MAXN; j += i) {
      cnt += A[j];
    }
    if (cnt > 1)
      ok = 0;
  }
  if (ok)
    printf("pairwise coprime");
  else if (ans == 1)
    printf("setwise coprime");
  else
    printf("not coprime");
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int A[2000005];

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

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &A[i]);
  for (int i = 1; i <= n - 1; ++i) {
    int flag = 0;
    for (int j = i + 1; j <= n; ++j)
      if (gcd(A[i], A[j]) != 1) {
        flag = 1;
        break;
      }
    if (flag == 1)
      break;
    if (i == n - 1) {
      printf("pairwise coprime");
      return 0;
    }
  }
  int G = gcd(A[1], A[2]);
  for (int i = 3; i <= n; ++i) {
    G = gcd(G, A[i]);
    if (G == 1) {
      printf("setwise coprime");
      return 0;
    }
  }
  printf("not coprime");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(c) begin(c), end(c)
template <typename T1, typename T2> bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2> bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
/*
全部の数の約数とりたい


各桁毎の素数の数一覧
範囲	0の数	素数の個数
10まで	10^1	1	4
100まで	10^2	2	25
1000まで	10^3	3	168
1万まで	10^4	4	1229
10万まで	10^5	5	9592
100万まで	10^6	6	78498
1000*10^6まで
*/
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  ll N;
  cin >> N;
  vector<ll> A(N, 0), B(1000010, 0);
  ll ans = 2;
  rep(k, N) {
    ll a;
    cin >> a;
    for (ll i = 2; i * i <= a; i++) {
      if (a % i == 0) {
        if (B[i] > 0)
          ans = 1;
        B[i]++;
        while (a % i == 0)
          a /= i;
      }
    }
    if (a > 1) {
      if (B[a] > 0)
        ans = 1;
      B[a]++;
    }
  }
  if (ans == 2) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  for (ll i = 2; i <= 1000000; i++) {
    if (B[i] == N) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(c) begin(c), end(c)
template <typename T1, typename T2> bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2> bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
/*
全部の数の約数とりたい


各桁毎の素数の数一覧
範囲	0の数	素数の個数
10まで	10^1	1	4
100まで	10^2	2	25
1000まで	10^3	3	168
1万まで	10^4	4	1229
10万まで	10^5	5	9592
100万まで	10^6	6	78498
1000*10^6まで
*/
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  ll N;
  cin >> N;
  vector<ll> A(N, 0);
  rep(i, N) cin >> A[i];
  ll ans = 2;
  map<ll, ll> MP;
  rep(k, N) {
    ll a = A[k];
    for (ll i = 2; i * i <= a; i++) {
      if (a % i == 0) {
        if (MP[i] > 0)
          ans = 1;
        MP[i]++;
        while (a % i == 0)
          a /= i;
      }
    }
    if (a > 1) {
      if (MP[a] > 0)
        ans = 1;
      MP[a]++;
    }
  }
  if (ans == 2) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  for (auto v : MP) {
    if (v.second == N) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n];
  rep(i, n) { cin >> a[i]; }
  // sort(a,a+n);
  int dp[1000003]{};

  bool z = false;
  rep(i, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        if (dp[j] != 0) {
          z = true;
          break;
        } else {
          dp[j] = 1;
          while (q % j == 0)
            q /= j;
        }
      }
    }
    if (q != 1 && dp[q] == 1) {
      z = true;
      break;
    } else if (q != 1) {
      dp[q] = 1;
    }
    if (z)
      break;
  }
  // rep(i,n){
  //     if(a[i]==a[i+1]){
  //         z=true;
  //         break;
  //     }

  //     for(int j=1;a[i]*j<=a[n-1];j++){
  //         if(j==1&&dp[a[i]*j]!=0){
  //             z=true;
  //             break;
  //             //z=true;
  //         }else dp[a[i]*j]=1;
  //     }
  //     if(z)break;
  // }
  // //cout<<z << " ";
  // rep(i,20)cout<<dp[i]<<" ";
  if (z == false) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int p = a[0];
  for (int i = 1; i < n; i++) {
    p = __gcd(p, a[i]);
  }
  if (p == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n];
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  int dp[100003]{};

  bool z = false;
  rep(i, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        if (dp[j] != 0) {
          z = true;
          break;
        } else {
          dp[j] = 1;
          while (q % j == 0)
            q /= j;
        }
      }
    }
    if (q != 1 && dp[q] == 1) {
      z = true;
      break;
    } else if (q != 1) {
      dp[q] = 1;
    }
    if (z)
      break;
  }
  // rep(i,n){
  //     if(a[i]==a[i+1]){
  //         z=true;
  //         break;
  //     }

  //     for(int j=1;a[i]*j<=a[n-1];j++){
  //         if(j==1&&dp[a[i]*j]!=0){
  //             z=true;
  //             break;
  //             //z=true;
  //         }else dp[a[i]*j]=1;
  //     }
  //     if(z)break;
  // }
  // //cout<<z << " ";
  // rep(i,20)cout<<dp[i]<<" ";
  if (z == false) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int p = a[0];
  for (int i = 1; i < n; i++) {
    p = __gcd(p, a[i]);
  }
  if (p == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}