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

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const int Nmax = 2e5 + 1;
const int Nd = 61;
const int INF = 1e5;

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     // 最小公倍数

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  bool pc = true;
  ll sgcd = 1;
  ll temp;
  ll minP = 2;
  bool furui = false;
  vector<bool> exist(1010101, false);

  rep(i, n) {
    cin >> a[i];
    if (i == 1) {
      sgcd = gcd(a[0], a[1]);
    }
    if (i > 1) {
      sgcd = gcd(sgcd, a[i]);
    }

    temp = a[i];
    furui = false;
    if (pc) {
      for (ll k = 2; k * k <= temp; k++) {
        if (temp % k != 0)
          continue;

        while (temp % k == 0) {
          temp /= k;
        }

        if (exist[k]) {
          pc = false;
          break;
        }
        exist[k] = true;
      }
      if (temp != 1 && exist[temp]) {
        pc = false;
        break;
      }
      exist[temp] = true;
    }
  }

  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  if (sgcd == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const int Nmax = 2e5 + 1;
const int Nd = 61;
const int INF = 1e5;

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     // 最小公倍数

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  bool pc = true, sc = true;
  ll sgcd;
  rep(i, n) {
    cin >> a[i];
    if (i == 1) {
      sgcd = gcd(a[0], a[1]);
    }
    if (i > 1) {
      sgcd = gcd(sgcd, a[i]);
    }
    if (pc) {
      for (int j = 0; j < i; j++) {
        if (gcd(a[i], a[j]) != 1) {
          pc = false;
          break;
        }
      }
    }
  }

  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  if (sgcd == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
// 999999997000000003
// 1000000000000000000

using namespace std;

const ll A = 1000005;

ll euclidean_gcd(ll a, ll b) {
  if (a < b)
    return euclidean_gcd(b, a);
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b; // あまりが0ならそれが、最大公約数
}

int solve() {
  ll N;
  cin >> N;
  vector<ll> a(N, 0);
  string pc = "pairwise coprime";
  string sc = "setwise coprime";
  string nc = "not coprime";

  vector<ll> c(A, 0);
  REP(i, N) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool pairwise = true;
  for (int i = 2; i < A; i++) {
    int cnt = 0;
    // iの倍数が複数あったらアウト
    for (int j = i; j < A; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) {
      pairwise = false;
    }
  }
  if (pairwise) {
    cout << pc << endl;
    return 0;
  }

  int g = a[0];
  for (int i = 1; i < N; ++i) {
    g = euclidean_gcd(g, a[i]);
  }
  if (g == 1) {
    cout << sc << endl;
    return 0;
  }

  cout << nc << endl;

  return 0;
}

int main() {
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
// 999999997000000003
// 1000000000000000000

using namespace std;

ll euclidean_gcd(ll a, ll b) {
  if (a < b)
    return euclidean_gcd(b, a);
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b; // あまりが0ならそれが、最大公約数
}

int solve() {
  ll N;
  cin >> N;
  vector<ll> a(N, 0);
  REP(i, N) cin >> a[i];
  string pc = "pairwise coprime";
  string sc = "setwise coprime";
  string nc = "not coprime";

  // すべての1 <= i < j <= Nにおいて GCD(Ai,Aj) = 1;
  // どのペアも素数同士

  // 2以上を分割していく?

  // 全部試してみる
  bool pcFlg = true;

  for (int i = 0; i < N - 1; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ll g;
      g = euclidean_gcd(a[i], a[j]);
      if (g != 1) {
        pcFlg = false;
        break;
      }
    }
  }

  if (pcFlg) {
    cout << pc << endl;
    return 0;
  }

  ll gc = euclidean_gcd(a[0], a[1]);

  for (int i = 2; i < N; ++i) {
    gc = euclidean_gcd(gc, a[i]);
  }

  if (gc == 1) {
    cout << sc << endl;
    return 0;
  }

  cout << nc << endl;
  return 0;
}

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

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

vector<int> prime_factors(int n) {
  vector<int> ans;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans.push_back(i);
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1)
    ans.push_back(n);
  return ans;
}

int cnt[1000010];

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int pairwise = 1;

  for (int i = 0; i < n; i++) {
    vector<int> v = prime_factors(a[i]);
    for (auto e : v) {
      cnt[e]++;
    }
  }

  for (auto e : cnt) {
    pairwise &= (e <= 1);
  }

  if (pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    int g = a[0];
    for (int i = 1; i < n; i++) {
      g = __gcd(g, a[i]);
    }
    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 int long long

const int mod = 1e9 + 7;

const int N = 200200;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

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

  int pairwise = 1;
  for (int i = 0; i < n; i++) {
    bool ok = 1;
    for (int j = i + 1; j < n; j++) {
      ok &= (__gcd(a[i], a[j]) == 1);
    }
    pairwise &= ok;
  }

  if (pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    int g = a[0];
    for (int i = 1; i < n; i++) {
      g = __gcd(g, a[i]);
    }
    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;
bool br[2000000];
void siv() {
  memset(br, true, 2000000);
  int i, j;
  br[0] = false;
  br[1] = false;
  for (i = 2; i * i <= 2000000; i++) {
    if (br[i] == true) {
      for (j = i * i; j <= 2000000; j += i) {
        br[j] = false;
      }
    }
  }
}

int prime(int n) {
  int i, j;
  for (i = 2; i <= n; i++) {
    if (br[i] == true) {
      if (n % br[i] == 0) {
        return i;
      }
    }
  }
}
int main() {
  int n, i, j, gd;
  while (cin >> n) {
    siv();
    vector<int> v;
    map<int, int> mp;
    int x, c = 0, z;
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    gd = v[0];
    for (i = 1; i < n; i++) {
      gd = __gcd(gd, v[i]);
    }
    if (gd != 1) {
      cout << "not coprime" << endl;
    } else {
      int p;
      int flag = 0;
      for (i = 0; i < n; i++) {
        p = v[i];
        if (br[p] == true) {
          mp[p]++;
          if (mp[p] > 1) {
            flag = 1;
            break;
          }
        } else {
          for (j = 2; j <= p; j++) {
            if (br[j] == true) {
              if (p % j == 0) {
                mp[j]++;
              }
              if (mp[j] > 1) {
                flag = 1;
                break;
              }
            }
          }
        }
      }
      if (flag == 1)
        cout << "setwise coprime" << endl;
      else
        cout << "pairwise coprime" << endl;
      mp.clear();
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool br[2000000];
void siv() {
  memset(br, true, 2000000);
  int i, j;
  br[0] = false;
  br[1] = false;
  for (i = 2; i * i <= 2000000; i++) {
    if (br[i] == true) {
      for (j = i * i; j <= 2000000; j += i) {
        br[j] = false;
      }
    }
  }
}

int prime(int n) {
  int i, j;
  for (i = 2; i <= n; i++) {
    if (br[i] == true) {
      if (n % br[i] == 0) {
        return i;
      }
    }
  }
}
int main() {
  int n, i, j, gd;
  while (cin >> n) {
    siv();
    vector<int> v;
    map<int, int> mp;
    int x, c = 0, z;
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    gd = v[0];
    for (i = 1; i < n; i++) {
      gd = __gcd(gd, v[i]);
    }
    if (gd != 1) {
      cout << "not coprime" << endl;
    } else {
      int p;
      int flag = 0;
      for (i = 0; i < n; i++) {
        p = v[i];

        for (j = 2; j <= p; j++) {
          if (br[j] == true) {
            if (p % j == 0) {
              mp[j]++;
            }
            if (mp[j] > 1) {
              flag = 1;
              break;
            }
          }
        }
      }
      if (flag == 1)
        cout << "setwise coprime" << endl;
      else
        cout << "pairwise coprime" << endl;
      mp.clear();
    }
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int N;
int cnt[1 << 20];
int all = 0;
bool isp[1 << 20];
main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    cnt[A]++;
    all = gcd(all, A);
  }
  bool ok = true;
  for (int i = 2; i < 1 << 20; i++) {
    int sum = 0;
    for (int j = i; j < 1 << 20; j += i)
      sum += cnt[j];
    if (sum > 1)
      ok = false;
  }
  cout << (ok         ? "pairwise coprime"
           : all == 1 ? "setwise coprime"
                      : "not coprime")
       << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + 5;
int a[maxn];
int ans;
int gcd_(int aa, int bb) {
  int a = aa;
  int b = bb;
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return a;
}
void solve() {
  int N;
  cin >> N;
  int flag = 0;
  int flag2 = 0;
  int min_ = 1e9 + 5;
  int mindex;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    if (a[i] != 1 && a[i] < min_) {
      min_ = a[i];
      mindex = i;
    }
  }
  if (min_ == 1e9 + 5) {
    cout << "pairwise coprime";
    return;
  }
  int bns = 0;
  while (bns < N - 1) {
    bns = 0;
    int minn = 1e9 + 5;
    int index;
    for (int i = 1; i <= N; i++) {
      if (i == mindex)
        continue;
      if (a[i] == 1 || a[i] == 0) {
        if (a[i] != 1)
          flag = 1;
        else
          flag2 = 1;
        bns++;
        continue;
      }
      a[i] = gcd_(a[i], min_);
      if (a[i] != 1 && a[i] != 0 && a[i] < minn) {
        minn = a[i];
        index = i;
      }
    }
    if (bns >= N - 1)
      break;
    if (minn == 1e9 + 5) {
      continue;
    }
    min_ = minn;
    mindex = index;
  }
  if (flag == 0)
    cout << "pairwise coprime";
  else if (flag2 == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
}
int main() {
  int _ = 1;
  while (_--) {
    solve();
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const int A = 1000005;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int memo[1001000] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    memo[a[i]]++;
  }

  int gcdd = a[0];

  for (int i = 1; i < n; i++) {
    gcdd = __gcd(gcdd, a[i]);
  }
  // setwise coprime

  bool pairwise = true;

  for (int i = 2; i < A; i++) {
    int cnt = 0;
    for (int j = i; j < A; j += i) {
      cnt += memo[j];
    }
    if (cnt > 1) {
      pairwise = false;
      cout << (gcdd == 1 ? "setwise coprime" : "not coprime") << endl;
      return 0;
    }
  }

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

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;

const int A = 1000006;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);

  int memo[1001000] = {};

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

  sort(a.begin(), a.end());

  int totalgcd = a[0];

  for (int i = 1; i < n; i++) {
    totalgcd = __gcd(totalgcd, a[i]);
  }
  // if totalgcd = 1 setwise coprime

  bool flag = true;
  for (int i = 2; i < A; i++) {
    int cnt = 0;
    for (int j = i; j < A; j += i) {
      cnt += a[j];
    }
    if (cnt > 1) {
      cout << "pairwise coprime" << endl;
      return 0;
    }
  }

  cout << (totalgcd == 1 ? "setwise coprime" : "not coprime") << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

#define REP(a, b, c) for (ll a = b; a < (c); a++)
#define PER(a, b, c) for (ll a = b; a >= (c); a--)

inline ll ii() {
  ll x;
  cin >> x;
  return x;
}
inline string is() {
  string x;
  cin >> x;
  return x;
}
inline ld id() {
  ld x;
  cin >> x;
  return x;
}
inline void oi(ll x) { cout << x; }
inline void od(ld x) { cout << fixed << setprecision(10) << x; }
inline void os(string x) { cout << x; }
inline void oe() { cout << endl; }
inline void oie(ll x) {
  oi(x);
  oe();
}
inline void ode(ld x) {
  od(x);
  oe();
}
inline void ose(string x) {
  os(x);
  oe();
}
inline void maxin(ll &a, ll b) { a = max(a, b); }
inline void minin(ll &a, ll b) { a = min(a, b); }

ll m[1123456];

int main() {
  ll N = ii();
  ll g = 0;
  REP(i, 0, N) {
    ll a = ii();
    g = __gcd(g, a);
    m[a]++;
  }
  bool pc = true;
  REP(i, 2, 1123456) {
    ll x = 0;
    for (ll j = i; j < 1123456; j += i) {
      x += m[j];
    }
    if (x >= 2) {
      pc = false;
      break;
    }
  }
  if (pc) {
    ose("pairwise coprime");
    return 0;
  }
  if (g == 1) {
    ose("setwise coprime");
  } else {
    ose("not coprime");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

#define REP(a, b, c) for (ll a = b; a < (c); a++)
#define PER(a, b, c) for (ll a = b; a >= (c); a--)

inline ll ii() {
  ll x;
  cin >> x;
  return x;
}
inline string is() {
  string x;
  cin >> x;
  return x;
}
inline ld id() {
  ld x;
  cin >> x;
  return x;
}
inline void oi(ll x) { cout << x; }
inline void od(ld x) { cout << fixed << setprecision(10) << x; }
inline void os(string x) { cout << x; }
inline void oe() { cout << endl; }
inline void oie(ll x) {
  oi(x);
  oe();
}
inline void ode(ld x) {
  od(x);
  oe();
}
inline void ose(string x) {
  os(x);
  oe();
}
inline void maxin(ll &a, ll b) { a = max(a, b); }
inline void minin(ll &a, ll b) { a = min(a, b); }

bool pt[1123456];
void e(vector<ll> &ps) {
  REP(i, 0, 1123456) pt[i] = true;
  pt[0] = pt[1] = false;
  REP(i, 0, 1123456) {
    if (pt[i]) {
      for (int j = i + i; j < 1123456; j += i) {
        pt[j] = false;
      }
    }
  }
  REP(i, 0, 1123456) {
    if (pt[i]) {
      ps.push_back(i);
    }
  }
}

int main() {
  ll N = ii();
  map<ll, ll> m;
  vector<ll> ps;
  e(ps);

  REP(t, 0, N) {
    ll a = ii();
    for (ll i = 0; ps[i] <= a; i++) {
      if (a % ps[i] == 0) {
        m[ps[i]]++;
      }
    }
  }
  for (auto v : m) {
    ll n = v.second;
    if (n == N) {
      ose("not coprime");
      return 0;
    }
    if (n > 1) {
      ose("setwise coprime");
      return 0;
    }
  }
  ose("pairwise coprime");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

const int max_A = 1000005;

LL gcd(LL val1, LL val2) {
  LL _val_lrg = (val1 > val2) ? val1 : val2;
  LL _val_sml = (val1 > val2) ? val2 : val1;

  LL r = _val_lrg % _val_sml;
  if (r == 0) {
    return _val_sml;
  } else {
    return gcd(_val_sml, r);
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> C(max_A);
  REP(i, N) {
    cin >> A[i];
    C[A[i]]++;
  }

  bool blpairwise = true;
  for (int i = 2; i < max_A; i++) {
    int cnt = 0;
    for (int j = i; j < max_A; j += i) {
      cnt += C[j];
    }
    if (cnt > 1) {
      blpairwise = false;
      break;
    }
  }

  if (blpairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int x = A[0];
  FOR(k, 1, N) { x = gcd(x, A[k]); }

  if (x == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

LL gcd(LL val1, LL val2) {
  LL _val_lrg = (val1 > val2) ? val1 : val2;
  LL _val_sml = (val1 > val2) ? val2 : val1;

  LL r = _val_lrg % _val_sml;
  if (r == 0) {
    return _val_sml;
  } else {
    return gcd(_val_sml, r);
  }
}

int main() {
  int N;
  cin >> N;
  vector<LL> A(N);
  REP(i, N) cin >> A[i];

  sort(A.begin(), A.end());
  LL val = 1;
  REP(i, N) { val *= A[i]; }

  bool bl_pairwise_coprime = true;
  REP(i, N - 1) {
    val /= A[i];
    LL tmp = gcd(A[i], val);
    if (tmp != 1) {
      bl_pairwise_coprime = false;
      break;
    }
  }

  val = A[0];
  REP(i, N - 1) {
    val = gcd(val, A[i + 1]);
    if (val == 1)
      break;
  }
  bool bl_setwise_coprime = (val == 1) ? true : false;

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

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

struct Factorizer {
  int n;
  vector<int> minFactor;
  vector<bool> cnt;

  Factorizer(int max) {
    int i, j;
    n = max;
    minFactor.resize(n);
    cnt.resize(n, 0);
    iota(minFactor.begin(), minFactor.end(), 0);
    for (i = 2; i * i < n; i++) {
      if (minFactor[i] < i)
        continue;
      for (j = i * i; j < n; j += i) {
        if (minFactor[j] == j)
          minFactor[j] = i;
      }
    }
  }

  bool check(int x) {
    while (x > 1) {
      if (cnt[minFactor[x]])
        return 1;
      else
        cnt[minFactor[x]] = 1;

      int t = minFactor[x];
      while (x % t == 0) {
        x /= t;
      }
    }
    return 0;
  }
};

int main(int argc, char *argv[]) {
  int n, i, s;
  cin >> n;

  Factorizer f(1000001);
  vector<int> a(n);

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

  for (i = 0; i < n; i++) {
    if (f.check(a[i])) {
      break;
    }
  }
  if (i == n) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int c = gcd(a[0], a[1]);
  for (i = 2; i < n; i++) {
    c = gcd(c, a[i]);
    if (c == 1)
      break;
  }
  if (c == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

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

struct Factorizer {
  int n;
  vector<int> minFactor;
  vector<bool> cnt;

  Factorizer(int max) {
    int i, j;
    n = max;
    minFactor.resize(n);
    cnt.resize(n, 0);
    iota(minFactor.begin(), minFactor.end(), 0);
    for (i = 2; i * i < n; i++) {
      if (minFactor[i] < i)
        continue;
      for (j = i * i; j < n; j += i) {
        if (minFactor[j] == j)
          minFactor[j] = i;
      }
    }
  }

  bool check(int x) {
    while (x > 1) {
      if (cnt[minFactor[x]])
        return 1;
      else
        cnt[minFactor[x]] = 1;

      int t = minFactor[x];
      while (x % t == 0) {
        x /= t;
      }
    }
    return 0;
  }
};

int main(int argc, char *argv[]) {
  int n, i, s;
  cin >> n;

  Factorizer f(100001);
  vector<int> a(n);

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

  for (i = 0; i < n; i++) {
    if (f.check(a[i])) {
      break;
    }
  }
  if (i == n) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int c = gcd(a[0], a[1]);
  for (i = 2; i < n; i++) {
    c = gcd(c, a[i]);
    if (c == 1)
      break;
  }
  if (c == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}