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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  vector<int> primes;
  for (int i = 2; i <= 1e3; i++) {
    bool f = true;
    for (auto x : primes) {
      if (i % x == 0)
        f = false;
    }
    if (f)
      primes.push_back(i);
  }

  vector<bool> used(1e6 + 1, false);
  bool f = true;
  for (auto x : a) {
    if (x == 1)
      continue;
    for (auto p : primes) {
      if (x % p != 0)
        continue;
      if (used[p])
        f = false;
      if (x / p != 1 && used[x / p])
        f = false;
      used[p] = true;
      used[x / p] = true;
    }
    if (x > 1e3) {
      if (used[x])
        f = false;
      used[x] = true;
    }
  }

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

  int g = a[0];
  for (auto x : a) {
    g = __gcd(g, x);
  }
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  auto divisors = [](int x) {
    vector<int> ret;
    if (x == 1)
      return ret;
    int i = 2;
    while (x > 1) {
      if (x % i == 0)
        ret.push_back(i);
      while (x % i == 0)
        x /= i;
      i++;
    }
    return ret;
  };

  vector<bool> used(1e6 + 1, false);
  bool f = true;
  for (auto x : a) {
    auto d = divisors(x);
    for (auto y : d) {
      if (used[y]) {
        f = false;
      }
      used[y] = true;
    }
  }

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

  int g = a[0];
  for (auto x : a) {
    g = __gcd(g, x);
  }
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

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

#include <iostream>
#include <vector>
using namespace std;

const int A = 1000005;

int gcd(int x, int y) {
  int r;
  if (x < y)
    swap(x, y);
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main(void) {
  // Your code here!
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(A);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    c[a[i]]++;
  }
  bool pairwise = true;
  for (int i = 2; i < A; i++) {
    int cnt = 0;
    for (int j = i; j < A; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) {
      pairwise = false;
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

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


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int gcd(int x, int y) {
  int r;
  if (x < y)
    swap(x, y);
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  int flag = 0;
  int check = A.at(0);
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (gcd(A.at(i), A.at(j)) != 1)
        flag = 1;
    }
    check = gcd(check, A.at(i + 1));
  }
  if (flag == 1 && check == 1)
    flag = 2;
  if (flag == 0) {
    cout << "pairwise coprime" << endl;
  } else if (flag == 1) {
    cout << "not coprime" << endl;
  } else if (flag == 2) {
    cout << "setwise coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
typedef long long ll;

int mxn = 1e6 + 4;
vector<int> spf(mxn + 1);

void sieve() {
  for (int i = 1; i <= mxn; i++)
    spf[i] = i;
  for (int i = 2; i <= mxn; i += 2)
    spf[i] = 2;
  for (int i = 3; i * i <= mxn; i += 2) {
    if (spf[i] == i) {
      for (int j = i * i; j <= mxn; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}

bool isPairwiseCoprime(vector<int> &a) {
  vector<int> prime_cnt(mxn + 1);
  for (int x : a) {
    if (x == 1)
      continue;
    while (x > 1) {
      int fac = spf[x];
      prime_cnt[fac]++;
      if (prime_cnt[fac] > 1)
        return false;
      while (x % fac == 0)
        x /= fac;
    }
  }
  return true;
}

bool isSetwiseCoprime(vector<int> &a, int n) {
  int gcd = a[0];
  for (int i = 1; i < n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  return gcd == 1;
}

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

  if (isPairwiseCoprime(a)) {
    cout << "pairwise coprime\\n";
  } else if (isSetwiseCoprime(a, n)) {
    cout << "setwise coprime\\n";
  } else {
    cout << "not coprime\\n";
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
typedef long long ll;

int mxn = 1e6 + 4;
vector<int> primes;

void sieve() {
  vector<bool> isPrime(mxn + 1, true);
  for (int i = 2; i * i <= mxn; i++) {
    if (!isPrime[i])
      continue;
    for (int j = i * i; j <= mxn; j += i) {
      isPrime[j] = false;
    }
  }
  for (int i = 2; i <= mxn; i++) {
    if (isPrime[i])
      primes.push_back(i);
  }
}

bool isPairwiseCoprime(vector<int> &a) {
  for (int p : primes) {
    int cnt = 0;
    for (int x : a) {
      cnt += (x % p == 0);
    }
    if (cnt > 1)
      return false;
  }
  return true;
}

bool isSetwiseCoprime(vector<int> &a, int n) {
  int gcd = a[0];
  for (int i = 1; i < n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  return gcd == 1;
}

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

  if (isPairwiseCoprime(a)) {
    cout << "pairwise coprime\\n";
  } else if (isSetwiseCoprime(a, n)) {
    cout << "setwise coprime\\n";
  } else {
    cout << "not coprime\\n";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define int long long
#define all(x) x.begin(), x.end()
#define forn(i, x) for (int i = i; i < x; ++i)

using namespace std;

int INF = 1e16 + 7;

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

void solve() {
  int n;
  cin >> n;
  map<int, int> d;
  bool ch = 1;
  int g = 0;
  while (n--) {
    int x;
    cin >> x;
    if (!g)
      g = x;
    if (g != 1)
      g = gcd(g, x);
    if (ch) {
      for (int i = 2; i * i < x; ++i) {
        if (x % i == 0) {
          if (d[i]++)
            ch = 0;
          while (x % i == 0)
            x /= i;
        }
      }
      if (x != 1)
        if (d[x]++)
          ch = 0;
    }
  }
  if (ch)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}

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

  cout << setprecision(10) << fixed;

  solve();

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define int long long
#define all(x) x.begin(), x.end()
#define forn(i, x) for (int i = i; i < x; ++i)

using namespace std;

int INF = 1e16 + 7;

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

void solve() {
  int n;
  cin >> n;
  map<int, int> d;
  bool ch = 1;
  int g = 0;
  while (n--) {
    int x;
    cin >> x;
    if (!g)
      g = x;
    g = gcd(g, x);
    for (int i = 2; i * i < x; ++i) {
      if (x % i == 0) {
        if (d[i]++)
          ch = 0;
        while (x % i == 0)
          x /= i;
      }
    }
    if (x != 1)
      if (d[x]++)
        ch = 0;
  }
  if (ch)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}

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

  cout << setprecision(10) << fixed;

  solve();

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

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

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

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

  int MAX_A = 1e6 + 2;
  vector<int> is_prime(MAX_A, 1),
      min_prime(MAX_A); // min_prime[i] := i の最小の素因数
  is_prime[0] = is_prime[1] = 0;
  min_prime[0] = min_prime[1] = -1;
  // エラトステネス
  for (int i = 0; i < MAX_A; ++i) {
    if (is_prime[i]) {
      min_prime[i] = i;
      for (int j = 2; i * j < MAX_A; ++j) {
        is_prime[i * j] = 0;
        min_prime[i * j] = i;
      }
    }
  }

  if (N == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  // gcd(A[0], A[1], ..., A[N - 1]) == 1 ??
  int g = 0;
  for (int i = 0; i < N; ++i)
    g = gcd(g, A[i]);
  if (g != 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  vector<int> used(MAX_A);
  for (int i = 0; i < N; ++i) {
    set<int> element; // A[i] の素因数
    // 高速素因数分解
    int now = A[i];
    while (now != 1) {
      element.insert(min_prime[now]);
      now /= min_prime[now];
    }
    for (int e : element)
      ++used[e];
  }

  for (int i = 0; i < MAX_A; ++i) {
    if (used[i] > 1) {
      cout << "setwise coprime" << endl;
      return 0;
    }
  }

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


Error: TLE

Fixed submission:

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

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

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

  int i = 0, g = A[0];
  for (int i = 0; i < N; ++i)
    g = gcd(g, A[i]);
  if (g != 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  for (int w = 1; w < N; ++w) {
    for (int i = 0; i + w < N; ++i) {
      if (gcd(A[i], A[i + w]) != 1) {
        cout << "setwise coprime" << endl;
        return 0;
      }
    }
  }
  cout << "pairwise coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int Euclidean(int A, int B) {
  int temp;
  int ma = max(A, B), mb = min(A, B);
  while (mb != 0) {
    temp = mb;
    mb = ma % mb;
    ma = temp;
  }
  return ma;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  int D[1000001];
  int IN[1000001];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < 1000001; i++) {
    IN[i] = 0;
    D[i] = i;
  }
  for (int i = 2; i * i <= 1000000; i++) {
    for (int j = 1; j * i <= 1000000; j++) {
      D[j * i] = min(D[j * i], i);
    }
  }
  int gcd = A[0];
  for (int i = 1; i < N; i++) {
    gcd = Euclidean(gcd, A[i]);
  }
  bool pc = true;
  for (int i = 0; i < N; i++) {
    int tmp = A[i];
    while (tmp > 1) {
      if (IN[D[tmp]] > 0) {
        pc = false;
        break;
      } else {
        IN[D[tmp]]++;
        int div = D[tmp];
        while (tmp % div == 0)
          tmp /= div;
      }
    }
  }
  // for(int i=0;i<6;i++){
  // 	cout << IN[i] << endl;
  // }
  if (pc)
    cout << "pairwise coprime" << endl;
  else if (gcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

Error: TLE

Fixed submission:

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

int Euclidean(int A, int B) {
  int temp;
  int ma = max(A, B), mb = min(A, B);
  while (mb != 0) {
    temp = mb;
    mb = ma % mb;
    ma = temp;
  }
  return ma;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  int IN[1000001];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < 1000001; i++) {
    IN[i] = 0;
  }
  int gcd = A[0];
  bool pc = true;
  int t = A[0];
  for (int j = 2; j * j <= A[0]; j++) {
    while (t % j == 0) {
      IN[j]++;
      t /= j;
    }
  }
  if (t != 1) {
    IN[t]++;
  }
  for (int i = 1; i < N; i++) {
    gcd = Euclidean(gcd, A[i]);
    int tmp = A[i];
    for (int j = 2; j * j <= A[i]; j++) {
      bool nnow = true;
      while (tmp % j == 0) {
        if (IN[j] > 0 && nnow) {
          pc = false;
          break;
        }
        IN[j]++;
        tmp /= j;
        nnow = false;
      }
    }
    if (tmp != 1) {
      if (IN[tmp] > 0) {
        pc = false;
      }
      IN[tmp]++;
    }
  }
  // for(int i=0;i<6;i++){
  // 	cout << IN[i] << endl;
  // }
  if (pc)
    cout << "pairwise coprime" << endl;
  else if (gcd == 1)
    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;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int c[1000010];

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

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

  int g = 0;
  rep(i, n) g = gcd(g, a[i]);

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  rep(i, n) {
    cin >> a[i];
    m[a[i]]++;
  }

  sort(all(a));
  bool ok2 = true;
  vector<int> is_prime(a[n - 1] + 1, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < a[n - 1]; i++) {
    if (!is_prime[i])
      continue;
    bool ok = false;
    for (int j = i; j < a[n - 1]; j += i) {
      if (!ok) {
        if (m[j])
          ok = true;
      } else {
        if (m[j])
          ok2 = false;
      }
    }
  }

  int g = 0;
  rep(i, n) g = gcd(g, a[i]);

  if (ok2) {
    cout << "pairwise coprime" << endl;
  } else if (g == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

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

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

int main() {
  ll n, g = 0, cnt[1000005] = {};
  cin >> n;

  rep(i, n) {
    ll a;
    cin >> a;
    cnt[a]++;
    g = gcd(g, a);
  }
  bool ok = true;
  for (ll i = 2; i < 1000005; i++) {
    ll sum = 0;
    for (ll j = i; j < 1000005; j += i)
      sum += cnt[j];
    if (sum > 1)
      ok = false;
  }
  cout << (ok       ? "pairwise coprime"
           : g == 1 ? "setwise coprime"
                    : "not coprime")
       << endl;
  return 0;
}

Error: 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;

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

int main() {
  ll n, g = 0, cnt[100005] = {};
  cin >> n;

  rep(i, n) {
    ll a;
    cin >> a;
    cnt[a]++;
    g = gcd(g, a);
  }
  bool ok = true;
  for (ll i = 2; i < 100005; i++) {
    ll sum = 0;
    for (ll j = i; j < 100005; j += i)
      sum += cnt[j];
    if (sum > 1)
      ok = false;
  }
  cout << (ok       ? "pairwise coprime"
           : g == 1 ? "setwise coprime"
                    : "not coprime")
       << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: 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 = 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;
}

Error: 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 = 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;
}
Problem p02574 (C++) — buggy submission, verdict: 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(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;
  }
}


Error: 0

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(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;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

vector<u32> min_p(1000006);

int main() {
  u32 n;
  cin >> n;

  vector<u32> a(n);
  rep(i, n) cin >> a[i];

  min_p[0] = 1;
  for (u32 i = 1; i < min_p.size(); i++) {
    min_p[i] = i;
    for (u32 j = 2; j * j < i; j++) {
      if (i % j == 0) {
        min_p[i] = j;
        break;
      }
    }
  }

  bool sc = true;
  u32 g = gcd(a[0], a[1]);
  for (u32 i = 2; i < n; i++) {
    g = gcd(g, a[i]);
  }
  if (g != 1)
    sc = false;

  unordered_map<u32, u64> m;
  unordered_set<u32> plist;

  rep(i, n) {
    plist.clear();
    while (1) {
      plist.insert(min_p[a[i]]);
      a[i] /= min_p[a[i]];
      if (min_p[a[i]] == a[i]) {
        plist.insert(a[i]);
        break;
      }
    };

    for (auto d : plist) {
      m[d]++;
    }
  }

  bool pc = true;

  for (auto p : m) {
    if (p.first != 1 && p.second > 1)
      pc = false;
  }

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

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

vector<u32> min_p(100006);

int main() {
  u32 n;
  cin >> n;

  vector<u32> a(n);
  rep(i, n) cin >> a[i];

  min_p[0] = 1;
  for (u32 i = 1; i < min_p.size(); i++) {
    min_p[i] = i;
    for (u32 j = 2; j * j < i; j++) {
      if (i % j == 0) {
        min_p[i] = j;
        break;
      }
    }
  }

  unordered_map<u32, u32> m;

  rep(i, n) {
    do {
      m[min_p[a[i]]]++;
      a[i] /= min_p[a[i]];
    } while (min_p[a[i]] != min_p[a[i]]);
  }

  bool pc = true;
  bool sc = true;

  for (auto p : m) {
    if (p.second >= n)
      sc = false;
    if (p.second != 1)
      pc = false;
  }

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

  return 0;
}