prithivMLmods/Coder-Stat huggingface dataset:
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9 + 100;
const int S = 1e3 + 5;

vector<int> pr;
vector<int> isp(S, 1);
void sieve() {
  for (int p = 2; p < S; p++) {
    if (isp[p]) {
      pr.push_back(p);
      for (int j = p * 2; j < S; j += p) {
        isp[j] = 0;
      }
    }
  }
}

int n;
vector<int> a;
bool f1() {
  vector<int> occ(S, 0);
  for (auto it : a) {
    for (auto p : pr) {
      if (it % p == 0) {
        if (occ[p]) {
          return 0;
        }
        occ[p]++;
        while (it % p == 0) {
          it /= p;
        }
      }
    }
    if (it != 1) {
      if (occ[it]) {
        return 0;
      }
      occ[it]++;
    }
  }
  return 1;
}
bool f2() {
  int allGCD = a[0];
  for (int i = 1; i < n; i++) {
    allGCD = __gcd(allGCD, a[i]);
  }
  return allGCD == 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  sieve();
  // cout<<pr.size()<<'\n';
  // for (int i = 0; i < 5; i++){
  // 	cout<<pr[i]<<'\n';
  // }

  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (f1()) {
    cout << "pairwise coprime\n";
  } else if (f2()) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
  return 0;
}

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

using ll = long long;
const int INF = 1e9 + 100;
const int S = 1e3 + 5;

vector<int> pr;
vector<int> isp(S, 1);
void sieve() {
  for (int p = 2; p < S; p++) {
    if (isp[p]) {
      pr.push_back(p);
      for (int j = p * 2; j < S; j += p) {
        isp[j] = 0;
      }
    }
  }
}

int n;
vector<int> a;
bool f1() {
  vector<int> occ(1e6 + 5, 0);
  for (auto it : a) {
    for (auto p : pr) {
      if (it % p == 0) {
        if (occ[p]) {
          return 0;
        }
        occ[p]++;
        while (it % p == 0) {
          it /= p;
        }
      }
    }
    if (it != 1) {
      if (occ[it]) {
        return 0;
      }
      occ[it]++;
    }
  }
  return 1;
}
bool f2() {
  int allGCD = a[0];
  for (int i = 1; i < n; i++) {
    allGCD = __gcd(allGCD, a[i]);
  }
  return allGCD == 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  sieve();
  // cout<<pr.size()<<'\n';
  // for (int i = 0; i < 5; i++){
  // 	cout<<pr[i]<<'\n';
  // }

  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (f1()) {
    cout << "pairwise coprime\n";
  } else if (f2()) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define F first
#define S second
#define pb push_back
#define mp make_pair

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

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, i, j;

  cin >> n;
  ll a[i];

  ll prime[1000003];

  memset(prime, 0, sizeof(prime));

  for (i = 2; i < 1000001; i++) {
    if (prime[i] == 0) {
      for (j = i; j < 1000001; j += i) {
        prime[j] = i;
      }
    }
  }

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

  map<ll, ll> pf;

  for (i = 0; i < n; i++) {
    map<ll, ll> m;

    ll x = a[i];

    while (x != 1) {
      if (m.find(prime[x]) == m.end()) {
        m.insert(mp(prime[x], 1));
      }

      x /= prime[x];
    }

    for (auto it : m) {
      if (pf.find(it.first) != pf.end())
        pf.find(it.first)->second++;
      else
        pf.insert(mp(it.first, 1));
    }
  }

  ll flag1 = 0, flag2 = 0;
  for (auto it : pf) {
    if (it.second != 1)
      flag1 = 1;
    if (it.second == n)
      flag2 = 1;
  }

  if (flag1 == 0)
    cout << "pairwise coprime\n";
  else if (flag2 == 0)
    cout << "setwise coprime\n";
  else
    cout << "not coprime\n";
}

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

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

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, i, j;

  cin >> n;
  ll a[n];

  ll prime[1000003];

  memset(prime, 0, sizeof(prime));

  for (i = 2; i < 1000001; i++) {
    if (prime[i] == 0) {
      for (j = i; j < 1000001; j += i) {
        prime[j] = i;
      }
    }
  }

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

  map<ll, ll> pf;

  for (i = 0; i < n; i++) {
    map<ll, ll> m;

    ll x = a[i];

    while (x != 1) {
      if (m.find(prime[x]) == m.end()) {
        m.insert(mp(prime[x], 1));
      }

      x /= prime[x];
    }

    for (auto it : m) {
      if (pf.find(it.first) != pf.end())
        pf.find(it.first)->second++;
      else
        pf.insert(mp(it.first, 1));
    }
  }

  ll flag1 = 0, flag2 = 0;
  for (auto it : pf) {
    if (it.second != 1)
      flag1 = 1;
    if (it.second == n)
      flag2 = 1;
  }

  if (flag1 == 0)
    cout << "pairwise coprime\n";
  else if (flag2 == 0)
    cout << "setwise coprime\n";
  else
    cout << "not coprime\n";
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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;
}

int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll cnt[1000006];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll allgcd = a[0];
  rep(i, n) allgcd = __gcd(allgcd, a[i]);
  if (allgcd > 1) {
    cout << "not coprime" << endl;
  } else {
    // 与えられた数をそれぞれ素因数分解していく
    rep(i, n) {
      ll now = a[i];
      for (ll j = 2; j * j <= a[i]; j++) {
        if (now % j == 0) {
          while (now % j == 0)
            now /= j;
          cnt[j]++;
        }
      }
      if (now > 1)
        cnt[now]++;
    }
    for (int i = 2; i <= 1e6; i++) {
      if (cnt[i] > 1) {
        cout << "setwise coprime" << endl;
        return 0;
      }
    }
    cout << "pairwise coprime" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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;
}

int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll cnt[1000006];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll allgcd = a[0];
  rep(i, n) allgcd = __gcd(allgcd, a[i]);
  if (allgcd > 1) {
    cout << "not coprime" << endl;
  } else {
    // 与えられた数をそれぞれ素因数分解していく
    rep(i, n) {
      ll now = a[i];
      for (ll j = 2; j * j <= now; j++) {
        if (now % j == 0) {
          while (now % j == 0)
            now /= j;
          cnt[j]++;
        }
      }
      if (now > 1)
        cnt[now]++;
    }
    for (int i = 2; i <= 1e6; i++) {
      if (cnt[i] > 1) {
        cout << "setwise coprime" << endl;
        return 0;
      }
    }
    cout << "pairwise coprime" << endl;
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int arr[100001];
int main() {
  fast int n, z;
  cin >> n;
  int g;
  bool b = 1;
  for (int i = 0; i < n; i++) {
    cin >> z;
    if (i == 0)
      g = z;
    else
      g = __gcd(z, g);
    if (b) {
      int s = sqrt(z);
      for (int j = 2; j <= s; j++) {
        if (z % j == 0) {
          if (arr[j] != 0)
            b = 0;
          arr[j]++;
          while (z % j == 0)
            z /= j;
        }
      }
      if (z != 1) {
        if (arr[z] != 0)
          b = 0;
        arr[z]++;
      }
    }
  }
  if (b)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int arr[1000001];
int main() {
  fast int n, z;
  cin >> n;
  int g;
  bool b = 1;
  for (int i = 0; i < n; i++) {
    cin >> z;
    if (i == 0)
      g = z;
    else
      g = __gcd(z, g);
    if (b) {
      int s = sqrt(z);
      for (int j = 2; j <= s; j++) {
        if (z % j == 0) {
          if (arr[j] != 0)
            b = 0;
          arr[j]++;
          while (z % j == 0)
            z /= j;
        }
      }
      if (z != 1) {
        if (arr[z] != 0)
          b = 0;
        arr[z]++;
      }
    }
  }
  if (b)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int is_prime(int n) {

  int i;
  i = 2;

  if (n == 1) {
    return 0;

  } else if (n == 2) {
    return 1;

  } else {
    while (1) {
      if (n % i == 0) {
        return 0;

      } else if (n < i * i) {
        return 1;

      } else {
        i++;
      }
    }
  }

  return 0;
}

int gcd(int m, int n) {

  if (m % n == 0) {
    return n;
  } else {
    return gcd(n, m % n);
  }
}

int is_set(int b[1145140], int n) {

  int i;
  i = 2;

  if (n == 1)
    return 0;

  if (is_prime(n) == 1) {
    if (b[n] == 1) {
      return 1;
    } else {
      b[n] = 1;
    }

  } else {
    while (n % i > 0) {
      i++;
    }

    if (b[i] == 1) {
      return 1;

    } else {
      b[i] = 1;

      while (n % i == 0) {
        n /= i;
      }

      return is_set(b, n);
    }
  }

  return 0;
}

int main() {

  int i, N, GCD, D, set;
  cin >> N;

  int a[N];
  int b[100000];

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

  for (i = 0; i < 100; i++) {
    b[i] = 0;
  }

  for (i = 0; i < N; i++) {
    if (i == 0) {
      GCD = a[i];

    } else {
      D = gcd(GCD, a[i]);
      GCD = D;
    }

    if (GCD == 1)
      break;
  }

  if (GCD > 1) {
    cout << "not coprime\n";
    return 0;
  }

  for (i = 0; i < N; i++) {
    set = is_set(b, a[i]);
    if (set == 1) {
      cout << "setwise coprime\n";
      return 0;
    }
  }

  cout << "pairwise coprime\n";

  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int is_prime(int n) {

  int i;
  i = 2;

  if (n == 1) {
    return 0;

  } else if (n == 2) {
    return 1;

  } else {
    while (1) {
      if (n % i == 0) {
        return 0;

      } else if (n < i * i) {
        return 1;

      } else {
        i++;
      }
    }
  }

  return 0;
}

int gcd(int m, int n) {

  if (m % n == 0) {
    return n;
  } else {
    return gcd(n, m % n);
  }
}

int is_set(int b[1145140], int n) {

  int i;
  i = 2;

  if (n == 1)
    return 0;

  if (is_prime(n) == 1) {
    if (b[n] == 1) {
      return 1;
    } else {
      b[n] = 1;
    }

  } else {
    while (n % i > 0) {
      i++;
    }

    if (b[i] == 1) {
      return 1;

    } else {
      b[i] = 1;

      while (n % i == 0) {
        n /= i;
      }

      return is_set(b, n);
    }
  }

  return 0;
}

int main() {

  int i, N, GCD, D, set;
  cin >> N;

  int a[N];
  int b[1145140];

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

  for (i = 0; i < 100; i++) {
    b[i] = 0;
  }

  for (i = 0; i < N; i++) {
    if (i == 0) {
      GCD = a[i];

    } else {
      D = gcd(GCD, a[i]);
      GCD = D;
    }

    if (GCD == 1)
      break;
  }

  if (GCD > 1) {
    cout << "not coprime\n";
    return 0;
  }

  for (i = 0; i < N; i++) {
    set = is_set(b, a[i]);
    if (set == 1) {
      cout << "setwise coprime\n";
      return 0;
    }
  }

  cout << "pairwise coprime\n";

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

int main() {
  ll i, j, n, m;
  cin >> n;
  vector<ll> a(n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  map<ll, bool> mp;
  for (i = 0; i < n; i++) {
    ll cur = a[i];
    ll pr = 0;
    while (cur % 2 == 0) {
      cur /= 2;
      pr = 1;
    }
    if (pr == 1) {
      if (mp.find(2) == mp.end()) {
        mp[2] = 1;
      } else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\n";
        else
          cout << "not coprime\n";
        return 0;
      }
    }
    for (j = 3; j <= cur; j += 2) {
      ll pr = 0;
      while (cur % j == 0) {
        cur /= j;
        pr = 1;
      }
      if (pr == 1) {
        if (mp.find(j) == mp.end()) {
          mp[j] = 1;
        } else {
          ll gcd = 0;
          for (ll k = 0; k < n; k++)
            gcd = __gcd(gcd, a[k]);
          if (gcd == 1)
            cout << "setwise coprime\n";
          else
            cout << "not coprime\n";
          return 0;
        }
      }
    }
    if (cur != 1) {
      if (mp.find(cur) == mp.end())
        mp[cur] = 1;
      else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\n";
        else
          cout << "not coprime\n";
        return 0;
      }
    }
  }
  cout << "pairwise coprime\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

int main() {
  ll i, j, n, m;
  cin >> n;
  vector<ll> a(n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  map<ll, bool> mp;
  for (i = 0; i < n; i++) {
    ll cur = a[i];
    ll pr = 0;
    while (cur % 2 == 0) {
      cur /= 2;
      pr = 1;
    }
    if (pr == 1) {
      if (mp.find(2) == mp.end()) {
        mp[2] = 1;
      } else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\n";
        else
          cout << "not coprime\n";
        return 0;
      }
    }
    for (j = 3; j * j <= cur; j += 2) {
      ll pr = 0;
      while (cur % j == 0) {
        cur /= j;
        pr = 1;
      }
      if (pr == 1) {
        if (mp.find(j) == mp.end()) {
          mp[j] = 1;
        } else {
          ll gcd = 0;
          for (ll k = 0; k < n; k++)
            gcd = __gcd(gcd, a[k]);
          if (gcd == 1)
            cout << "setwise coprime\n";
          else
            cout << "not coprime\n";
          return 0;
        }
      }
    }
    if (cur != 1) {
      if (mp.find(cur) == mp.end())
        mp[cur] = 1;
      else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\n";
        else
          cout << "not coprime\n";
        return 0;
      }
    }
  }
  cout << "pairwise coprime\n";
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2> inline void chmax(T1 &a, const T2 &b) {
  if (a < b)
    a = b;
}

template <class T1, class T2> inline void chmin(T1 &a, const T2 &b) {
  if (a > b)
    a = b;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  int N;
  cin >> N;

  int max_num = 0;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    chmax(max_num, A[i]);
  }

  vector<int> prime(max_num + 1, 0);

  for (int i = 2; i < max_num + 1; ++i) {
    if (prime[i] == 0) {
      for (int j = i; j <= max_num + 1; j += i) {
        if (prime[j] == 0) {
          prime[j] = i;
        }
      }
    }
  }

  vector<int> s(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    int num = A[i];
    set<int> tmp;
    while (num != 1) {
      tmp.emplace(prime[num]);
      num /= prime[num];
    }
    for (auto x : tmp) {
      ++s[x];
    }
  }

  bool is_pairwise = true;
  for (auto x : s) {
    if (x == N) {
      cout << "not coprime" << endl;
      return 0;
    } else if (x > 1) {
      is_pairwise = false;
    }
  }
  if (is_pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2> inline void chmax(T1 &a, const T2 &b) {
  if (a < b)
    a = b;
}

template <class T1, class T2> inline void chmin(T1 &a, const T2 &b) {
  if (a > b)
    a = b;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  int N;
  cin >> N;

  int max_num = 0;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    chmax(max_num, A[i]);
  }

  vector<int> prime(max_num + 1, 0);

  for (int i = 2; i < max_num + 1; ++i) {
    if (prime[i] == 0) {
      for (int j = i; j <= max_num + 1; j += i) {
        if (prime[j] == 0) {
          prime[j] = i;
        }
      }
    }
  }

  vector<int> s(max_num + 1, 0);
  for (int i = 0; i < N; ++i) {
    int num = A[i];
    set<int> tmp;
    while (num != 1) {
      tmp.emplace(prime[num]);
      num /= prime[num];
    }
    for (auto x : tmp) {
      ++s[x];
    }
  }

  bool is_pairwise = true;
  for (auto x : s) {
    if (x == N) {
      cout << "not coprime" << endl;
      return 0;
    } else if (x > 1) {
      is_pairwise = false;
    }
  }
  if (is_pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int MX = 100003;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), c(MX, 0);
  rep(i, n) cin >> a[i], c[a[i]]++;

  ll g = 0;
  rep(i, n) g = __gcd(g, a[i]);

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

  bool pairwise = true;
  for (int i = 2; i < MX; ++i) {
    ll cnt = 0;
    for (int j = i; j < MX; j += i)
      cnt += c[j];
    if (cnt > 1)
      pairwise = false;
  }

  cout << (pairwise ? "pairwise coprime" : "setwise coprime") << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int MX = 1000003;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), c(MX, 0);
  rep(i, n) cin >> a[i], c[a[i]]++;

  ll g = 0;
  rep(i, n) g = __gcd(g, a[i]);

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

  bool pairwise = true;
  for (int i = 2; i < MX; ++i) {
    ll cnt = 0;
    for (int j = i; j < MX; j += i)
      cnt += c[j];
    if (cnt > 1)
      pairwise = false;
  }

  cout << (pairwise ? "pairwise coprime" : "setwise coprime") << endl;

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
// const int MAX = 1000005;
const int MAX = 60;
const int mod = 1000000007;
/* global variables */
vector<int> cnt(MAX, 0);
vector<int> a;
int N;
/* function */
int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
bool isPc1() {
  for (int i = 0; i < N; i++) {
    cnt[a[i]]++;
  }
  vector<bool> isPrime(MAX, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < MAX; i++) {
    int num = cnt[i];
    if (isPrime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        isPrime[j] = false;
        num += cnt[j];
      }
    }
    if (num >= 2)
      return false;
  }
  return true;
}
bool isSc() {
  int ret = 0;
  for (int i = 0; i < N; i++) {
    ret = gcd(ret, a[i]);
  }
  if (ret == 1)
    return true;
  else
    return false;
}
/* main */
int main() {
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];

  if (isPc1()) {
    cout << "pairwise coprime" << '\n';
  } else if (isSc()) {
    cout << "setwise coprime" << '\n';
  } else {
    cout << "not coprime" << '\n';
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int MAX = 1000005;
const int mod = 1000000007;
/* global variables */
vector<int> cnt(MAX, 0);
vector<int> a;
int N;
/* function */
int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
bool isPc1() {
  for (int i = 0; i < N; i++) {
    cnt[a[i]]++;
  }
  vector<bool> isPrime(MAX, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < MAX; i++) {
    int num = cnt[i];
    if (isPrime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        isPrime[j] = false;
        num += cnt[j];
      }
    }
    if (num >= 2)
      return false;
  }
  return true;
}
bool isSc() {
  int ret = 0;
  for (int i = 0; i < N; i++) {
    ret = gcd(ret, a[i]);
  }
  if (ret == 1)
    return true;
  else
    return false;
}
/* main */
int main() {
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];

  if (isPc1()) {
    cout << "pairwise coprime" << '\n';
  } else if (isSc()) {
    cout << "setwise coprime" << '\n';
  } else {
    cout << "not coprime" << '\n';
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_lr(i, l, r) for (int i = (l); i < (r); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; }

vi prime, mnpf;
void preprime(int n) {

  prime.resize(0);
  mnpf.assign(n + 1, 1);
  rep(i, n + 1) {
    if (i < 2)
      continue;
    if (mnpf[i] != 1)
      continue;

    prime.push_back(i);
    mnpf[i] = i;
    int ii = i;
    while (ii <= n) {
      if (mnpf[ii] == 1)
        mnpf[ii] = i;
      ii += i;
    }
  }
}

int main() {

  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  int g = a[0];
  rep(i, n) g = gcd(g, a[i]);
  if (g > 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  preprime(n + 1000);

  map<int, int> pri;

  rep(i, n) {
    int k = a[i];
    while (k > 1) {
      pri[mnpf[k]]++;
      int memo = mnpf[k];
      while (mnpf[k] == memo)
        k /= mnpf[k];
    }
  }

  bool pairwise = true;
  for (auto x : pri) {
    if (x.second > 1)
      pairwise = false;
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else
    cout << "setwise coprime" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_lr(i, l, r) for (int i = (l); i < (r); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; }

vi prime, mnpf;
void preprime(int n) {

  prime.resize(0);
  mnpf.assign(n + 1, 1);
  rep(i, n + 1) {
    if (i < 2)
      continue;
    if (mnpf[i] != 1)
      continue;

    prime.push_back(i);
    mnpf[i] = i;
    int ii = i;
    while (ii <= n) {
      if (mnpf[ii] == 1)
        mnpf[ii] = i;
      ii += i;
    }
  }
}

int main() {

  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  int g = a[0];
  rep(i, n) g = gcd(g, a[i]);
  if (g > 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  preprime(1010100);

  map<int, int> pri;

  rep(i, n) {
    int k = a[i];
    while (k > 1) {
      pri[mnpf[k]]++;
      int memo = mnpf[k];
      while (mnpf[k] == memo)
        k /= mnpf[k];
    }
  }

  bool pairwise = true;
  for (auto x : pri) {
    if (x.second > 1)
      pairwise = false;
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else
    cout << "setwise coprime" << endl;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

ll gcd(ll n, ll m) { // 最大公約数を求めるプログラム
  // nとmの最大公約数を返す関数
  if (m > n) {
    ll c = n;
    n = m;
    m = c;
  }
  if (n % m == 0ll)
    return m;
  else
    return gcd(m, n % m);
}

vector<ll> fpf_prepare(ll a) { // fpfの前処理　O(alog(loga))
  vector<ll> res;
  rp(i, 2, a + 1) {
    if (res[i] == 0) {
      for (int k = 1; i * k <= a; k++) {
        res[i * k] = i;
      }
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  auto D = fpf_prepare(1000010);
  vector<bool> p(1000010, false);
  bool flag = false;
  rp(i, 0, n) {
    ll a;
    scanf("%lld", &a);
    A.at(i) = a;
    ll m = 1000000ll;
    while (a > 1ll) {
      // cout << "a = " << a << " D[a] = " << D[a] << endl;
      if (D[a] < m && p[D[a]])
        flag = true;
      p[D[a]] = true;
      m = D[a];
      a /= D[a];
    }
  }

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

  ll g = A[0];
  rp(i, 1, n) {
    g = gcd(g, A[i]);
    if (g == 1) {
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "not coprime" << endl;
  return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

ll gcd(ll n, ll m) { // 最大公約数を求めるプログラム
  // nとmの最大公約数を返す関数
  if (m > n) {
    ll c = n;
    n = m;
    m = c;
  }
  if (n % m == 0ll)
    return m;
  else
    return gcd(m, n % m);
}

vector<ll> fpf_prepare(ll a) { // fpfの前処理　O(alog(loga))
  vector<ll> res(a + 1);
  rp(i, 2, a + 1) {
    if (res[i] == 0) {
      for (int k = 1; i * k <= a; k++) {
        res[i * k] = i;
      }
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  auto D = fpf_prepare(1000010);
  vector<bool> p(1000010, false);
  bool flag = false;
  rp(i, 0, n) {
    ll a;
    scanf("%lld", &a);
    A.at(i) = a;
    ll m = 1000000ll;
    while (a > 1ll) {
      // cout << "a = " << a << " D[a] = " << D[a] << endl;
      if (D[a] < m && p[D[a]])
        flag = true;
      p[D[a]] = true;
      m = D[a];
      a /= D[a];
    }
  }

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

  ll g = A[0];
  rp(i, 1, 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 (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int nax = 2e5 + 7;

int lpf[nax], mobius[nax];

void least_prime_factor() {
  for (int i = 2; i < nax; i++) {
    if (!lpf[i]) {
      for (int j = i; j < nax; j += i) {
        if (!lpf[j]) {
          lpf[j] = i;
        }
      }
    }
  }
  return;
}
void mob() {
  for (int i = 1; i < nax; i++) {
    if (i == 1) {
      mobius[i] = 1;
    } else {
      if (lpf[i / lpf[i]] == lpf[i]) {
        mobius[i] = 0;
      } else {
        mobius[i] = -1 * mobius[i / lpf[i]];
      }
    }
  }
  return;
}
int gp(int a[], int n) {
  int maxi = 0;
  int fre[nax] = {0};
  for (int i = 0; i < n; i++) {
    fre[a[i]]++;
    maxi = max(a[i], maxi);
  }
  least_prime_factor();
  mob();
  int ans = 0;
  for (int i = 1; i <= maxi; i++) {
    if (!mobius[i]) {
      continue;
    }
    int temp = 0;
    for (int j = i; j <= maxi; j += i) {
      temp += fre[j];
    }
    ans += temp * (temp - 1) / 2 * mobius[i];
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  int pairs = gp(a, n);
  if (pairs == (n * (n - 1)) / 2) {
    cout << "pairwise coprime\n";
    return 0;
  }
  if (gcd == 1) {
    cout << "setwise coprime\n";
    return 0;
  }
  cout << "not coprime\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int nax = 1e6 + 7;

int lpf[nax], mobius[nax];

void least_prime_factor() {
  for (int i = 2; i < nax; i++) {
    if (!lpf[i]) {
      for (int j = i; j < nax; j += i) {
        if (!lpf[j]) {
          lpf[j] = i;
        }
      }
    }
  }
  return;
}
void mob() {
  for (int i = 1; i < nax; i++) {
    if (i == 1) {
      mobius[i] = 1;
    } else {
      if (lpf[i / lpf[i]] == lpf[i]) {
        mobius[i] = 0;
      } else {
        mobius[i] = -1 * mobius[i / lpf[i]];
      }
    }
  }
  return;
}
int gp(int a[], int n) {
  int maxi = 0;
  int fre[nax] = {0};
  for (int i = 0; i < n; i++) {
    fre[a[i]]++;
    maxi = max(a[i], maxi);
  }
  least_prime_factor();
  mob();
  int ans = 0;
  for (int i = 1; i <= maxi; i++) {
    if (!mobius[i]) {
      continue;
    }
    int temp = 0;
    for (int j = i; j <= maxi; j += i) {
      temp += fre[j];
    }
    ans += temp * (temp - 1) / 2 * mobius[i];
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  int pairs = gp(a, n);
  if (pairs == (n * (n - 1)) / 2) {
    cout << "pairwise coprime\n";
    return 0;
  }
  if (gcd == 1) {
    cout << "setwise coprime\n";
    return 0;
  }
  cout << "not coprime\n";
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define fio                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

void solution() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int &x : A)
    cin >> x;
  int g = A[0];
  map<int, int> c;
  for (int x : A) {
    g = __gcd((unsigned)g, (unsigned)x);
    c[x]++;
  }
  if (g > 1) {
    cout << "not coprime" << endl;
    return;
  }
  int m = *max_element(all(A));
  for (int i = 2; i <= m; i++) {
    int cur = 0;
    for (int j = i; j <= m; j += i) {
      cur += c[j];
    }
    if (cur > 1) {
      cout << "setwise coprime" << endl;
      return;
    }
  }
  cout << "pairwise coprime" << endl;
  return;
}

int main() {
  fio;
  int t;
  t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";
    solution();
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define fio                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

void solution() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int &x : A)
    cin >> x;
  int g = A[0];
  unordered_map<int, int> c;
  for (int x : A) {
    g = __gcd((unsigned)g, (unsigned)x);
    c[x]++;
  }
  if (g > 1) {
    cout << "not coprime" << endl;
    return;
  }
  int m = *max_element(all(A));
  for (int i = 2; i <= m; i++) {
    int cur = 0;
    for (int j = i; j <= m; j += i) {
      cur += c[j];
    }
    if (cur > 1) {
      cout << "setwise coprime" << endl;
      return;
    }
  }
  cout << "pairwise coprime" << endl;
  return;
}

int main() {
  fio;
  int t;
  t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";
    solution();
  }
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007
const int N = 1e6 + 5;
ll cnt[N];
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll gc = a[0];
  for (int i = 1; i < n; i++) {
    gc = gcd(gc, a[i]);
  }
  if (gc > 1) {
    cout << "not coprime";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    ll t = a[i];
    for (int j = 2; j * j <= a[i]; j++) {
      if (t % j == 0) {
        while (t % j == 0) {
          t /= j;
        }
        cnt[j]++;
      }
    }
    if (t > 1) {
      cnt[t]++;
    }
  }
  bool flag = 1;
  for (auto it : cnt) {
    if (it > 1) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime";
  } else {
    cout << "setwise coprime";
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007
const int N = 1e6 + 5;
ll cnt[N];
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll gc = a[0];
  for (int i = 1; i < n; i++) {
    gc = gcd(gc, a[i]);
  }
  if (gc > 1) {
    cout << "not coprime";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    ll t = a[i];
    for (int j = 2; j * j <= t; j++) {
      if (t % j == 0) {
        while (t % j == 0) {
          t /= j;
        }
        cnt[j]++;
      }
    }
    if (t > 1) {
      cnt[t]++;
    }
  }
  bool flag = 1;
  for (auto it : cnt) {
    if (it > 1) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime";
  } else {
    cout << "setwise coprime";
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int N = 100010;
vector<int> prime;     // i番目の素数
bool is_prime[100011]; // is_prime[i] がTrueならiは素数

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
  return p; // pは素数の数
}

int main() {
  sieve(N);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(N);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }
  bool flag = true;
  for (int i : prime) {
    int cnt = 0;
    for (int j = i; j <= N; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) {
      flag = false;
      break;
    }
  }
  int gcd = a[0];
  rep(i, n - 1) { gcd = __gcd(a[i + 1], gcd); }
  if (flag)
    cout << "pairwise coprime" << endl;
  else if (gcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int N = 1000100;
vector<int> prime;      // i番目の素数
bool is_prime[1000100]; // is_prime[i] がTrueならiは素数

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
  return p; // pは素数の数
}

int main() {
  sieve(N);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(N);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }
  bool flag = true;
  for (int i : prime) {
    int cnt = 0;
    for (int j = i; j <= N; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) {
      flag = false;
      break;
    }
  }
  int gcd = a[0];
  rep(i, n - 1) { gcd = __gcd(a[i + 1], gcd); }
  if (flag)
    cout << "pairwise coprime" << endl;
  else if (gcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9 + 7
typedef long long int ll;
const int maxn = 1000000;
ll mod = INF;

int d[maxn + 1];
int n;
int a[maxn];
int cnt[maxn + 1];
int used[maxn + 1];
int ans = 0;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i <= maxn; i++)
    d[i] = INF;
  d[0] = d[1] = 1;
  sort(a, a + n);
  for (int div = 2; div <= a[n - 1]; div++) {
    for (int bediv = 2; bediv <= a[n - 1]; bediv++) {
      if (d[bediv] == INF) {
        if (bediv % div == 0) {
          d[bediv] = div;
        }
      }
    }
  }

  for (int i = 0; i < n; i++) {
    int bediv = a[i];
    set<int> s;
    while (bediv > 1) {
      s.insert(d[bediv]);
      bediv = bediv / d[bediv];
    }
    for (auto ite = s.begin(); ite != s.end(); ite++) {
      used[*ite]++;
      if (used[*ite] > 1) {
        ans = 1;
        break;
      }
    }
    if (ans == 1)
      break;
  }

  set<int> t;
  int temp = a[0];
  while (temp > 1) {
    t.insert(d[temp]);
    temp = temp / d[temp];
  }

  for (auto ite = t.begin(); ite != t.end(); ite++) {
    for (int i = 0; i < n; i++) {
      if (a[i] % *ite != 0)
        break;
      if (i == n - 1)
        ans = 2;
    }
    if (ans == 2)
      break;
  }

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

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9 + 7
typedef long long int ll;
const int maxn = 1000000;
ll mod = INF;

int d[maxn + 1];
int n;
int a[maxn];
int cnt[maxn + 1];
int used[maxn + 1];
int ans = 0;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i <= maxn; i++)
    d[i] = INF;
  d[0] = d[1] = 1;
  sort(a, a + n);
  for (int div = 2; div <= a[n - 1]; div++) {
    if (d[div] != INF)
      continue;
    for (int bediv = div; bediv <= a[n - 1]; bediv += div) {
      d[bediv] = div;
    }
  }

  for (int i = 0; i < n; i++) {
    int bediv = a[i];
    set<int> s;
    while (bediv > 1) {
      s.insert(d[bediv]);
      bediv = bediv / d[bediv];
    }
    for (auto ite = s.begin(); ite != s.end(); ite++) {
      used[*ite]++;
      if (used[*ite] > 1) {
        ans = 1;
        break;
      }
    }
    if (ans == 1)
      break;
  }

  set<int> t;
  int temp = a[0];
  while (temp > 1) {
    t.insert(d[temp]);
    temp = temp / d[temp];
  }

  for (auto ite = t.begin(); ite != t.end(); ite++) {
    for (int i = 0; i < n; i++) {
      if (a[i] % *ite != 0)
        break;
      if (i == n - 1)
        ans = 2;
    }
    if (ans == 2)
      break;
  }

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

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

const int MAX = 1e6;
vector<int> prime(MAX + 1, -1);

void settable() {
  for (int i = 2; i <= MAX; i++) {
    if (prime[i] == -1) {
      prime[i] = i;
      for (int j = i + i; j <= MAX; j += i) {
        prime[j] = i;
      }
    }
  }
}

int main() {
  settable();
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> ok(MAX + 1, false);
  bool ok1 = true, ok2 = true;
  for (int i = 0; i < n; i++) {
    int nn = a[i];
    set<int> s;
    do {
      int d = prime[nn];
      s.insert(d);
      nn /= d;
    } while (nn > 1);

    for (auto dd : s) {
      if (ok[dd])
        ok1 = false;
      ok[dd] = true;
    }
  }

  int G = 0;
  for (int i = 0; i < n; i++) {
    G = gcd(a[i], G);
  }
  ok2 = (G == 1);
  if (ok1) {
    cout << "pairwise coprime" << endl;
  } else if (ok2) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

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

template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

const int MAX = 1e6;
vector<int> prime(MAX + 1, -1);

void settable() {
  for (int i = 2; i <= MAX; i++) {
    if (prime[i] == -1) {
      prime[i] = i;
      for (int j = i + i; j <= MAX; j += i) {
        prime[j] = i;
      }
    }
  }
}

int main() {
  settable();
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> ok(MAX + 1, false);
  bool ok1 = true, ok2 = true;
  for (int i = 0; i < n; i++) {
    int nn = a[i];
    if (nn == 1)
      continue;
    set<int> s;
    do {
      int d = prime[nn];
      s.insert(d);
      nn /= d;
    } while (nn > 1);

    for (auto dd : s) {
      if (ok[dd])
        ok1 = false;
      ok[dd] = true;
    }
  }

  int G = 0;
  for (int i = 0; i < n; i++) {
    G = gcd(a[i], G);
  }
  ok2 = (G == 1);
  if (ok1) {
    cout << "pairwise coprime" << endl;
  } else if (ok2) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second
#define all(A) A.begin(), A.end()

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9 + 7)
#define vv vector

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

ll N, A[202020];

ll i, j, k;

int main() {
  scanf("%lld", &N);
  rep(i, 0, N) { scanf("%lld", &A[i]); }
  j = A[0];
  rep(i, 1, N) { j = gcd(j, A[i]); }

  if (j != 1) {
    printf("not coprime\n");
    return 0;
  }
  const ll Amx = 1010101;
  vv<ll> mk(Amx + 10), mk2(Amx + 10);
  rep(i, 0, N) { ++mk2[A[i]]; }
  rep(i, 2, Amx) {
    if (mk[i]) {
      continue;
    }
    ll a = 0;
    for (j = i; j < Amx; j += i) {
      ++mk[j];
      a += mk2[j];
    }
    if (a >= 2)
      break;
  }
  if (i == Amx) {
    printf("pairwise coprime\n");
  } else {
    printf("setwise coprime\n");
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second
#define all(A) A.begin(), A.end()

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9 + 7)
#define vv vector

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

ll N, A[1010101];

ll i, j, k;

int main() {
  scanf("%lld", &N);
  rep(i, 0, N) { scanf("%lld", &A[i]); }
  j = A[0];
  rep(i, 1, N) { j = gcd(j, A[i]); }

  if (j != 1) {
    printf("not coprime\n");
    return 0;
  }
  const ll Amx = 1010101;
  vv<ll> mk(Amx + 10), mk2(Amx + 10);
  rep(i, 0, N) { ++mk2[A[i]]; }
  rep(i, 2, Amx) {
    if (mk[i]) {
      continue;
    }
    ll a = 0;
    for (j = i; j < Amx; j += i) {
      ++mk[j];
      a += mk2[j];
    }
    if (a >= 2)
      break;
  }
  if (i == Amx) {
    printf("pairwise coprime\n");
  } else {
    printf("setwise coprime\n");
  }

  return 0;
}