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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
int main() {
  int N, ans, i;
  cin >> N;
  int A[N];
  REP(i, N) cin >> A[i];
  ans = A[0];
  REP(i, N - 1) ans = __gcd(ans, A[i + 1]);
  if (ans == 1) {
    int x = 1;
    vector<int> X;
    REP(i, N) {
      int j = 1;
      while (A[i] != 1) {
        j++;
        if (j * j > A[i]) {
          X.push_back(A[i]);
          break;
        }
        if (A[i] % j == 0) {
          X.push_back(j);
          while (A[i] % j == 0)
            A[i] /= j;
        }
      }
      if (X.size() > 78498)
        break;
    }
    if (X.size())
      sort(ALL(X));
    if (X.size() > 1)
      REP(i, X.size() - 1) if (X.at(i) == X.at(i + 1)) x = 0;
    if (x == 1)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
int main() {
  int N, ans, i;
  cin >> N;
  int A[N];
  REP(i, N) cin >> A[i];
  ans = A[0];
  REP(i, N - 1) ans = __gcd(ans, A[i + 1]);
  if (ans == 1) {
    int x = 1;
    vector<int> X;
    REP(i, N) {
      int j = 1;
      while (A[i] != 1) {
        j++;
        if (j * j > A[i]) {
          X.push_back(A[i]);
          break;
        }
        if (A[i] % j == 0) {
          X.push_back(j);
          while (A[i] % j == 0)
            A[i] /= j;
        }
      }
      if (X.size() > 78498)
        break;
    }
    sort(ALL(X));
    REP(i, X.size() - 1) if (X.at(i) == X.at(i + 1)) x = 0;
    if (x == 1)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
// const ll mod=998244353;
const ll mod = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll c, ll d) { return c / GCD(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
vector<int> prime;
void make(ll num) {
  prime.resize(num + 1, 0);
  for (ll i = 2; i <= num; i++) {
    if (!prime[i]) {
      for (ll j = i; j <= num; j += i) {
        if (!prime[j])
          prime[j] = i;
      }
    }
  }
}
ll cnt[1000005];
int main() {
  make(1000005);
  int n;
  cin >> n;
  ll a, d;
  ll g = -1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (g == -1)
      g = a;
    else
      g = GCD(g, a);
    while (a > 1) {
      cnt[prime[a]]++;
      d = prime[a];
      while (a % d == 0)
        a /= d;
    }
  }
  bool ok = true;
  for (int i = 2; i < 1000005; i++) {
    if (cnt[i] >= 2)
      ok = false;
  }
  if (ok) {
    cout << "pairwise coprime"
         << "\\n";
  } else {
    cout << (g == 1 ? "setwise coprime" : "not coprime") << "\\n";
  }
}


Error: 0

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
// const ll mod=998244353;
const ll mod = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll c, ll d) { return c / GCD(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
vector<int> prime;
void make(ll num) {
  prime.resize(num + 1, 0);
  for (ll i = 2; i * i <= num; i++) {
    if (!prime[i]) {
      for (ll j = i; j <= num; j += i) {
        if (!prime[j])
          prime[j] = i;
      }
    }
  }
}
ll cnt[1000005];
int main() {
  make(1000005);
  int n;
  cin >> n;
  ll a, d;
  ll g = -1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (g == -1)
      g = a;
    else
      g = GCD(g, a);
    while (a > 1) {
      cnt[prime[a]]++;
      d = prime[a];
      while (a % d == 0)
        a /= d;
    }
  }
  bool ok = true;
  for (int i = 2; i < 100005; i++) {
    if (cnt[i] >= 2)
      ok = false;
  }
  if (ok) {
    cout << "pairwise coprime"
         << "\\n";
  } else {
    cout << (g == 1 ? "setwise coprime" : "not coprime") << "\\n";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

//
// Created by PIIMUU on 8/29/2020.
//
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int fgcd(int x, int y) {
  if (y > x) {
    swap(x, y);
  }
  while (y != 0) {
    int temp = y;
    y = x % y;
    x = temp;
  }
  return x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<bool> prime(1e6 + 10, true);
  prime[1] = false;
  for (int i = 2; i * i <= 1e6; i++) {
    if (prime[i] == true) {
      for (int j = i + i; j <= 1e6; j += i) {
        prime[j] = false;
      }
    }
  }
  set<int> s;
  for (int i = 2; i <= 1e6; i++) {
    if (prime[i] == true) {
      s.insert(i);
    }
  }
  int gcd = 0;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    gcd = fgcd(gcd, a[i]);
  }
  if (gcd == 1) {
    sort(a.begin() + 1, a.end());
    bool yes = true;
    for (int i = 1; i <= n; i++) {
      if (a[i] == 1) {
        continue;
      }
      if (s.size() == 0) {
        yes = false;
      }
      auto p = s.begin();
      set<int> t;
      while (a[i] > 1) {
        if (p == s.end()) {
          break;
        }
        if (a[i] % *p == 0) {
          a[i] /= *p;
          t.insert(*p);
        } else {
          p++;
        }
      }
      if (a[i] > 1) {
        yes = false;
        break;
      }
      for (auto x : t) {
        s.erase(x);
      }
    }
    if (yes == true) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  } else {
    cout << "not coprime";
  }
}

Error: TLE

Fixed submission:

//
// Created by PIIMUU on 8/29/2020.
//
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int fgcd(int x, int y) {
  if (y > x) {
    swap(x, y);
  }
  while (y != 0) {
    int temp = y;
    y = x % y;
    x = temp;
  }
  return x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  /*
  vector<bool> prime(1e6 + 10, true);
  prime[1] = false;
  for (int i = 2; i * i <= 1e6; i++) {
      if (prime[i] == true) {
          for (int j = i + i; j <= 1e6; j += i) {
              prime[j] = false;
          }
      }
  }
  */
  int gcd = 0;
  vector<int> cnt(1e6 + 10), a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    // gcd = fgcd(gcd, a[i]);
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (j != 1) {
          cnt[j]++;
        }
        if (a[i] / j != j) {
          cnt[a[i] / j]++;
        }
      }
    }
  }
  bool yes = true;
  for (int i = 1; i <= 1e6; i++) {
    if (cnt[i] > 1) {
      yes = false;
    }
  }
  if (yes == true) {
    cout << "pairwise coprime";
    return 0;
  }
  for (int i = 1; i <= 1e6; i++) {
    if (cnt[i] >= n) {
      cout << "not coprime";
      return 0;
    }
  }
  cout << "setwise coprime";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
using namespace std;

const int maxn = 1020;
const int maxm = 1000050;
ll p[maxm], a[maxm], s[maxm], cnt = 0;
bool vis[maxm];

void init() {
  for (int i = 2; i < maxn; ++i) {
    if (!vis[i])
      p[cnt++] = i;
    for (int j = 0; j < cnt && p[j] * i < maxn; ++j) {
      vis[p[j] * i] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
int main() {
  init();
  int n, mx = 0;
  cin >> n;
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x > mx)
      mx = x;
    for (int j = 0; j < cnt; ++j)
      if (x % p[j] == 0) {
        s[p[j]]++;
        while (x % p[j] == 0) {
          x /= p[j];
        }
      }
    if (x > 1)
      s[x]++;
  }
  int f1 = 1, f2 = 1;
  for (int i = 1; i < mx; ++i) {
    if (s[i] > 1)
      f1 = 0;
    if (s[i] == n)
      f2 = 0;
  }
  if (f1) {
    cout << "pairwise coprime" << endl;
  } else {
    if (f2) {
      cout << "setwise coprime" << endl;
    } else
      cout << "not coprime" << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
using namespace std;

const int maxn = 10050;
const int maxm = 1000050;
ll p[maxm], a[maxm], s[maxm], cnt = 0;
bool vis[maxm];

void init() {
  for (int i = 2; i < maxn; ++i) {
    if (!vis[i])
      p[cnt++] = i;
    for (int j = 0; j < cnt && p[j] * i < maxn; ++j) {
      vis[p[j] * i] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
int main() {
  init();
  int n, mx = 0;
  cin >> n;
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x > mx)
      mx = x;
    for (int j = 0; j < cnt; ++j)
      if (x % p[j] == 0) {
        s[p[j]]++;
        while (x % p[j] == 0) {
          x /= p[j];
        }
      }
    if (x > 1)
      s[x]++;
  }
  int f1 = 1, f2 = 1;
  for (int i = 1; i < mx; ++i) {
    if (s[i] > 1)
      f1 = 0;
    if (s[i] == n)
      f2 = 0;
  }
  if (f1) {
    cout << "pairwise coprime" << endl;
  } else {
    if (f2) {
      cout << "setwise coprime" << endl;
    } else
      cout << "not coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL n;
  cin >> n;

  vector<LL> a(n);

  for (auto &e : a) {
    cin >> e;
  }

  LL net_gcd = a[0];
  for (LL i = 1; i < n; ++i) {
    net_gcd = __gcd(net_gcd, a[i]);
  }

  if (net_gcd != 1) {
    cout << "not coprime\\n";
    return 0;
  }
  vector<LL> primes(N, 0);
  for (LL i = 0; i < n; ++i) {
    LL x = a[i];

    for (LL j = 2; j * j <= x; ++j) {
      if (x % j == 0) {
        while (x % j == 0)
          x /= j;
        primes[j]++;
      }
    }
    if (x > 1) {
      primes[x]++;
    }
  }

  for (auto e : primes) {
    if (e > 1) {
      cout << "setwise coprime\\n";
      return 0;
    }
  }
  cout << "pairwise coprime\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL n;
  cin >> n;

  vector<LL> a(n);

  for (auto &e : a) {
    cin >> e;
  }

  LL net_gcd = a[0];
  for (LL i = 1; i < n; ++i) {
    net_gcd = __gcd(net_gcd, a[i]);
  }

  if (net_gcd != 1) {
    cout << "not coprime\\n";
    return 0;
  }
  vector<LL> primes(N, 0);
  for (LL i = 0; i < n; ++i) {
    LL x = a[i];

    for (LL j = 2; j * j <= a[i]; ++j) {
      if (x % j == 0) {
        while (x % j == 0)
          x /= j;
        primes[j]++;
      }
    }
    if (x > 1) {
      primes[x]++;
    }
  }

  for (auto e : primes) {
    if (e > 1) {
      cout << "setwise coprime\\n";
      return 0;
    }
  }
  cout << "pairwise coprime\\n";

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

#include <iostream>
#include <vector>
using namespace std;
const int LIM = 1000010;
int mygcd(int a, int b) {
  if (a < b) {
    int t = a;
    a = b;
    b = t;
  }
  while (b) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int gcd_a = a[0];
  for (int i = 1; i < n; i++)
    gcd_a = mygcd(a[i], gcd_a);

  if (gcd_a > 1) {
    cout << "not coprime" << endl;
  } else {
    vector<int> is_prime(LIM);
    for (int i = 0; i < LIM; i++)
      is_prime[i] = i;
    for (int i = 2; i < LIM; i++) {
      if (is_prime[i] == i) {
        for (int j = 2; i * j < LIM; j++) {
          is_prime[i * j] = i;
        }
      }
    }

    bool is_pairwise = true;
    vector<bool> is_used(LIM, false);
    for (int i = 0; i < n; i++) {
      int tmp = a[i];
      while (tmp > 1) {
        int p = is_prime[tmp];
        if (is_used[p]) {
          is_pairwise = false;
          break;
        } else {
          is_used[p] = true;
          while (tmp % p == 0)
            tmp /= p;
        }
      }
    }

    if (is_pairwise)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
const int LIM = 1000010;
int mygcd(int a, int b) {
  if (a < b) {
    int t = a;
    a = b;
    b = t;
  }
  while (b) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int gcd_a = a[0];
  for (int i = 1; i < n; i++)
    gcd_a = mygcd(a[i], gcd_a);

  if (gcd_a > 1) {
    cout << "not coprime" << endl;
  } else {
    vector<int> is_prime(LIM);
    for (int i = 0; i < LIM; i++)
      is_prime[i] = i;
    for (int i = 2; i < LIM; i++) {
      if (is_prime[i] == i) {
        for (int j = 2; i * j < LIM; j++) {
          is_prime[i * j] = i;
        }
      }
    }

    bool is_pairwise = true;
    vector<bool> is_used(LIM, false);
    for (int i = 0; i < n; i++) {
      int tmp = a[i];
      for (int j = is_prime[a[i]]; tmp >= j; j++) {
        if (tmp % j == 0) {
          if (is_used[j]) {
            is_pairwise = false;
            break;
          } else {
            is_used[j] = true;
            while (tmp % j == 0)
              tmp /= j;
          }
        }
      }
      if (!is_pairwise)
        break;
    }

    if (is_pairwise)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 200010;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int n, m, a[maxn * 5];
bool prime[maxn * 5];
string s, ss;

vector<int> generate_prime(int n) {
  vector<int> v;
  map<int, int> M;
  v.clear(), M.clear();
  while (n % 2 == 0)
    M[2] = 1, n /= 2;
  for (int i = 3; i * i < n; i += 2)
    while (n % i == 0)
      n /= i, M[i] = 1;
  if (n > 2)
    v.push_back(n);
  for (auto u : M)
    v.push_back(u.first);
  return v;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int gcd = a[0];
  for (int i = 1; i < n; i++)
    gcd = __gcd(gcd, a[i]);
  bool ok = true;
  map<int, int> M;
  for (int i = 0; i < n; i++) {
    vector<int> v;
    v = generate_prime(a[i]);
    for (auto u : v)
      M[u]++;
    v.clear();
  }
  for (auto u : M)
    if (u.second > 1)
      ok = false;
  if (ok)
    cout << "pairwise coprime\\n";
  else if (gcd == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}


Error: 0

Fixed submission:

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 200010;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int n, m, a[maxn];
string s, ss;

vector<int> generate_prime(int a) {
  map<int, int> M;
  int i = 2;
  while (a %= i) {
    a /= i, i++;
    M[i] = 1;
  }
  vector<int> v;
  for (auto u : M)
    v.push_back(u.first);
  return v;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int gcd = a[0];
  for (int i = 1; i < n; i++)
    gcd = __gcd(gcd, a[i]);
  bool ok = true;
  map<int, int> M;
  for (int i = 0; i < n; i++) {
    vector<int> v;
    v = generate_prime(a[i]);
    for (auto u : v)
      M[u]++;
  }
  for (auto u : M)
    if (u.second > 1)
      ok = false;
  if (!ok)
    cout << "pairwise coprime\\n";
  else if (gcd == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

const int N = 1000005;
bool is_prime[N + 5];
int d[N + 5]; // d[i]=iの最小の素因数
int mp[N + 5];
int main() {
  for (int i = 0; i < N; i++)
    is_prime[i] = true; // エラトステネス
  for (int i = 2; i < N; i++) {
    if (is_prime[i])
      d[i] = i;
    for (int j = i + i; j < N; j += i) {
      is_prime[j] = false;
      if (is_prime[i] && d[j] == 0)
        d[j] = i;
    }
  }

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> p;
  for (int i = 0; i < n; i++) {
    while (a[i] > 1) {
      int m = d[a[i]];
      a[i] /= m;
      if (a[i] % m != 0)
        p.push_back(m);
    }
  }
  for (auto x : p)
    mp[x]++;
  int ans = 0;
  for (int i = 1; i < N + 5; i++) {
    if (mp[i] >= 2 && mp[i] <= n - 1)
      ans = 1;
    if (mp[i] == n) {
      ans = 2;
      break;
    }
  }
  if (ans == 0)
    cout << "pairwise coprime" << endl;
  if (ans == 1)
    cout << "setwise coprime" << endl;
  if (ans == 2)
    cout << "not coprime" << endl;
  return 0;
}


Error: 0

Fixed submission:

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

const int N = 1e6;
bool is_prime[N + 5];
int d[N + 5]; // d[i]=iの最小の素因数
int mp[N + 5];
int main() {
  for (int i = 0; i < N; i++)
    is_prime[i] = true; // エラトステネス
  for (int i = 2; i < N; i++) {
    if (is_prime[i])
      d[i] = i;
    for (int j = i + i; j < N; j += i) {
      is_prime[j] = false;
      if (is_prime[i] && d[j] == 0)
        d[j] = i;
    }
  }

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> p;
  for (int i = 0; i < n; i++) {
    while (a[i] > 1) {
      int m = d[a[i]];
      a[i] /= m;
      if (a[i] % m != 0)
        p.push_back(m);
    }
  }
  for (auto x : p)
    mp[x]++;
  int ans = 0;
  for (int i = 1; i < N + 5; i++) {
    if (mp[i] >= 2 && mp[i] <= n - 1)
      ans = 1;
    if (mp[i] == n) {
      ans = 2;
      break;
    }
  }
  if (ans == 0)
    cout << "pairwise coprime" << endl;
  if (ans == 1)
    cout << "setwise coprime" << endl;
  if (ans == 2)
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define cf ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define fox(i, n) for (int i = 0; i < n; i++)
#define srtar(a, n) sort(a, a + n)
#define srtvec(v) sort(v.begin(), v.end())
#define fauto(x, t) for (auto x : t)
#define mem(n, x) memset(n, x, sizeof(n))
const ll mac = 2e5;
bool cum[mac + 10];
vector<ll> acn, prit;
void siv() {
  ll i, j, k;
  mem(cum, true);
  cum[0] = cum[1] = false;
  for (i = 2; i <= mac; i++) {
    if (cum[i]) {
      prit.push_back(i);
      for (j = i * i; j <= mac; j += i) {
        cum[i] = false;
      }
    }
  }
}
map<ll, ll> mp;
void pf(ll n) {
  ll i, j, p = 0;
  for (i = 0; i < prit.size(); i++) {
    //	 cout << p << "  p  ";
    p = prit[i];
    //  cout << p << "  p  ";
    if (p * p > n)
      break;
    if (n % p == 0) {
      while (n % p == 0) {
        n /= p;
      }
      //   cout << p << "  popk  ";
      mp[p]++;
    }
    //   cout << p << "  p  ";
  }
  if (n != 1)
    mp[n]++;
}
int main() {
  siv();
  ll t, m, g, n;
  cin >> n;
  ll a[n];
  fox(i, n) {
    cin >> a[i];
    pf(a[i]);
    if (i == 0)
      g = a[0];
    else {
      g = __gcd(g, a[i]);
    }
  }
  int y = 1;
  for (auto x : mp) {
    //	cout << x.second << " " << x.first  << " , ";
    if (x.second != 1) {
      //	cout << x.second << " " << x.first ;
      y = 0;
      break;
    }
  }
  if (y)
    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;
bool pri[10020];
int fac[1000005];
vector<int> v;
void sieve() {
  int i, j, n = 10000;
  for (i = 2; i <= n; i++)
    pri[i] = true;
  pri[0] = pri[1] = false;
  for (i = 2; i * i <= n; i++) {
    for (j = i * i; j <= n; j += i)
      pri[j] = false;
  }
  for (i = 2; i <= n; i++) {
    if (pri[i])
      v.push_back(pri[i]);
  }
}
// map<int,int>fac;
void fact(int n) {
  int i, j, k;
  for (i = 0; i < v.size(); i++) {
    k = v[i];
    if (k * k > n)
      break;
    if (n % k == 0) {
      while (n % k == 0) {
        n /= k;
      }
      fac[k]++;
    }
  }
  if (k > 1)
    fac[k]++;
}
int main() {
  sieve();
  int i, j, k, t, x, n;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    fact(a[i]);
  }
  x = 1;
  for (i = 2; i <= 1000000; i++) {
    if (fac[i] > 1) {
      x = 0;
      break;
    }
  }
  if (x)
    cout << "pairwise coprime";
  else {
    t = a[0];
    for (i = 1; i < n; i++) {
      t = __gcd(t, a[i]);
    }
    if (t == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  }
  return 0;
}