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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll mod = 1e9 + 7;
bool prime[1000005];
ll arr[1000001], spf[1000001];
vector<ll> primes;
unordered_map<ll, bool> seen;
ll good = 1;

void sieve() {
  // cout<<"n sicve ";
  ll n = 1000000;
  for (ll i = 0; i <= n; i++) {
    if (i % 2 == 0)
      prime[i] = 0;
    else
      prime[i] = 1;
    if (i % 2 != 0)
      spf[i] = i;
    else
      spf[i] = 2;
  }
  // cout<<"n sicve 2";

  prime[2] = 1;
  prime[1] = 0;
  primes.pb(2);

  for (ll i = 3; i <= n; i += 2) {
    if (spf[i] == i) {
      for (ll j = i * i; j <= n; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}

void primefactorize(ll n) {
  ll prev = -1;
  while (n > 1) {
    if (spf[n] != prev && seen[spf[n]])
      good = 0;
    seen[spf[n]] = 1;
    prev = spf[n];
    n /= spf[n];
  }
}

int main() {
  sieve();
  // for(int i=0;i<10;i++) cout<<primes[i]<<" ";cout<<endl;
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll g = arr[0];
  for (int i = 0; i < n; i++) {
    primefactorize(arr[i]);
    g = __gcd(g, arr[i]);
    ;
  }
  if (good)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll mod = 1e9 + 7;
bool prime[1000005];
ll arr[1000001];
vector<ll> primes;
unordered_map<ll, bool> seen;
ll good = 1;

void sieve() {
  // cout<<"n sicve ";
  ll n = 1000000;
  for (ll i = 0; i <= n; i++)
    if (i % 2 == 0)
      prime[i] = 0;
    else
      prime[i] = 1;
  // cout<<"n sicve 2";

  prime[2] = 1;
  prime[1] = 0;
  primes.pb(2);

  for (ll i = 3; i <= n; i += 2) {
    if (prime[i]) {
      // cout<<i<<" ";
      primes.pb(i);
      for (ll j = i * i; j <= n; j += i)
        prime[j] = 0;
    }
  }
}

void primefactorize(ll n) {
  if (n == 1)
    return;
  if (prime[n]) {
    if (seen[n])
      good = 0;
    seen[n] = 1;
    return;
  }
  for (int i = 0; i < primes.size() && n > 1; i++) {
    if (n % primes[i] == 0) {
      if (seen[primes[i]])
        good = 0;
      while (n % primes[i] == 0) {
        n /= primes[i];
        // cout<<primes[i]<<" ";
      }

      seen[primes[i]] = 1;
    }
  }
}

int main() {
  sieve();
  // for(int i=0;i<10;i++) cout<<primes[i]<<" ";cout<<endl;
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll g = arr[0];
  for (int i = 0; i < n; i++) {
    primefactorize(arr[i]);
    g = __gcd(g, arr[i]);
    ;
  }
  if (good)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t;

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (a[i] > m)
      m = a[i];
    if (g)
      g = gcd(g, a[i]);
    else
      g = a[0];
  }
  if (g > 1) {
    printf("not coprime\\n");
    return 0;
  }
  for (i = 2; i <= m; i++) {
    if (sieve[i] == 0) {
      sieve[i] = i;
      if ((long long)i * i <= m)
        for (j = i * i; j <= m; j += i) {
          if (sieve[j] == 0)
            sieve[j] = i;
        }
    }
  }
  for (i = 0; i < n; i++) {
    j = a[i];
    while (j > 1) {
      t = sieve[j];
      cnt[t]++;
      if (cnt[t] > 1) {
        printf("setwise coprime\\n");
        return 0;
      }
      while (j % t == 0)
        j /= t;
    }
  }
  printf("pairwise coprime\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t;

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (a[i] > m)
      m = a[i];
    if (g)
      g = gcd(g, a[i]);
    else
      g = a[0];
  }
  if (g > 1) {
    printf("not coprime\\n");
    return 0;
  }
  for (i = 2; i <= m; i++) {
    if (sieve[i] == 0) {
      sieve[i] = i;
      for (j = i * i; j <= m; j += i) {
        if (sieve[j] == 0)
          sieve[j] = i;
      }
    }
  }
  for (i = 0; i < n; i++) {
    j = a[i];
    while (j > 1) {
      t = sieve[j];
      cnt[t]++;
      if (cnt[t] > 1) {
        printf("setwise coprime\\n");
        return 0;
      }
      while (j % t == 0)
        j /= t;
    }
  }
  printf("pairwise coprime\\n");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

const ll inf = 1000000007;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}

int gcd(int n, int m) {
  if (n < m) {
    swap(n, m);
  }
  int r = n % m;
  while (r) {
    n = m;
    m = r;
    r = n % m;
  }
  return m;
}

int prime[1000005], ji = 0;
int pa[1000005], a[1000005], n, p[1000005], b[1000005];

int main() {
  pa[0] = pa[1] = 1;
  for (ll i = 2; i <= 1000000; i++) {
    if (!pa[i]) {
      prime[ji++] = i;
      for (ll j = i * i; j <= 1000000; j = j + i) {
        pa[j] = 1;
      }
    }
  }
  n = read();
  int jj = 0;
  int ma = -1, flag = 1;
  for (int i = 0; i < n; i++) {
    a[jj] = read();
    b[i] = a[jj];
    if (!pa[a[jj]]) {
      p[a[jj]]++;
      if (p[a[jj]] > 1) {
        flag = 0;
      }
    } else
      jj++;
  }
  if (flag) {
    for (int i = 0; i < jj; i++) {
      for (int j = 0; j <= ji && prime[j] <= a[i]; j++) {
        if (a[i] % prime[j] == 0) {
          if (p[prime[j]] != 0) {
            flag = 0;
            j = inf;
            i = inf;
            break;
          }
          while (a[i] % prime[j] == 0) {
            p[prime[j]]++;
            a[i] = a[i] / prime[j];
          }
          if (!pa[a[i]]) {
            if (p[a[i]] != 0) {
              flag = 0;
              j = inf;
              i = inf;
              break;
            }
            p[a[i]]++;
            break;
          }
        }
      }
    }
  }
  if (flag) {
    printf("pairwise coprime\\n");
  } else {
    int g = b[0];
    for (int i = 1; i < n; i++) {
      g = gcd(g, b[i]);
    }
    if (g == 1) {
      printf("setwise coprime\\n");
    } else {
      printf("not coprime\\n");
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

const ll inf = 1000000007;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}

int prime[1000005], ji = 0;
int pa[1000005], a[1000005], n;

int main() {
  pa[0] = pa[1] = 1;
  for (ll i = 2; i <= 1000000; i++) {
    if (!pa[i]) {
      prime[ji++] = i;
      for (ll j = i * i; j <= 1000000; j = j + i) {
        pa[j] = 1;
      }
    }
  }
  n = read();
  for (int i = 0; i < n; i++) {
    a[i] = read();
  }
  int ma = -1;
  for (int i = 0; i < ji; i++) {
    int p = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] % prime[i] == 0) {
        p++;
      }
    }
    ma = max(p, ma);
  }
  if (ma == 1) {
    printf("pairwise coprime\\n");
  } else if (ma == n) {
    printf("not coprime\\n");
  } else {
    printf("setwise coprime\\n");
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  vector<int> primes;
  primes.push_back(2);
  for (int i = 3; i <= 500000; i = i + 2) {
    int flag = 1;
    for (int j = 3; j <= sqrt(i); j = j + 2) {
      if (i % j == 0) {
        flag = 0;
        break;
      }
    }
    if (flag == 1)
      primes.push_back(i);
  }
  int n;
  cin >> n;
  map<int, int> m;
  int maxx = INT_MIN;
  int soul = 0;
  int amma = 0;
  for (int i = 0; i < n; ++i) {
    int temp;
    cin >> temp;
    maxx = max(maxx, temp);
    if (temp % 2 == 0)
      amma++;
    if (i == 0) {
      soul = temp;
    } else {
      soul = __gcd(soul, temp);
    }
    m[temp]++;
  }
  if (amma >= 2) {
    if (soul == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
    return 0;
  }
  int flag = 0;
  for (int k = 0; k < primes.size(); ++k) {
    int i = primes[k];
    int j = 1;
    int bokka = 0;
    while (i * j <= maxx) {
      if (m[i * j] >= 2) {
        flag = 1;
        break;
      }
      if (m[i * j] == 1)
        bokka++;
      if (bokka == 2) {
        flag = 1;
        break;
      }
      j++;
    }
    if (flag == 1)
      break;
  }
  if (flag == 0) {
    cout << "pairwise coprime" << endl;
  } else if (soul == 1) {
    cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  int maxx = INT_MIN;
  int soul;
  for (int i = 0; i < n; ++i) {

    int temp;
    cin >> temp;
    maxx = max(maxx, temp);
    if (i == 0) {
      soul = temp;
    } else {
      soul = __gcd(soul, temp);
    }
    m[temp]++;
  }
  int flag = 0;
  for (int i = 2; i <= 500000; ++i) {
    int j = 1;
    int bokka = 0;
    while (i * j <= maxx) {
      if (m[i * j] >= 2) {
        flag = 1;
        break;
      }
      if (m[i * j] == 1)
        bokka++;
      if (bokka == 2) {
        flag = 1;
        break;
      }
      j++;
    }
    if (flag == 1)
      break;
  }
  if (flag == 0) {
    cout << "pairwise coprime" << endl;
  } else if (soul == 1) {
    cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;

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


// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define endl '\\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}
const int N = 1e6 + 5;
int prime[N];
int vis[N + 5];
int cnt[N], k = 0;
void seive() {
  prime[k++] = 2;
  for (int i = 3; i < N; i += 2) {
    if (!vis[i]) {
      prime[k++] = i;
      for (int j = 3 * i; j <= N; j += 2 * i)
        vis[j] = 1;
    }
  }
}
int main() {
  ios;
  seive();
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    int a = ar[i];
    if (ar[i] == 1) {
      cnt[1] = 1;
    }

    else {
      for (int k1 = 0; prime[k1] * prime[k1] <= a && k1 < k; k1++) {
        if (a % prime[k1] == 0) {
          while (a % prime[k1] == 0) {
            a /= prime[k1];
          }
          cnt[prime[k1]]++;
        }
      }
      if (a != 1)
        cnt[a]++;
    }
  }
  int mx = *max_element(cnt, cnt + N);
  if (mx == 1)
    cout << "pairwise coprime" << endl;
  else if (mx < n)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: TLE

Fixed submission:


// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define endl '\\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}
const int N = 1e6 + 5;
vector<int> prime;
int vis[N + 5];
int cnt[N];
void seive() {
  vis[0] = vis[1] = 1;
  prime.pb(2);
  for (int i = 3; i < N; i += 2) {
    if (!vis[i]) {
      prime.pb(i);
      for (int j = 3 * i; j <= N; j += 2 * i)
        vis[j] = 1;
    }
  }
}
int main() {
  ios;
  seive();
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    int a = ar[i];
    if (ar[i] == 1) {
      cnt[1] = 1;
    }

    else {
      for (int k = 0; prime[k] * prime[k] <= a && k < prime.size(); k++) {
        if (a % prime[k] - 1) {
          while (a % prime[k] - 1) {
            a /= prime[k];
          }
          cnt[prime[k]]++;
        }
      }
      if (a != 1)
        cnt[a]++;
    }
  }
  int mx = *max_element(cnt, cnt + N);
  if (mx == 1)
    cout << "pairwise coprime" << endl;
  else if (mx < n)
    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;
#define ll long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  fastio ll n, t, i, j, x, k;
  cin >> n;
  ll b[1000001] = {0};

  for (i = 2; i * i < 1000001; i++) {
    if (b[i] == 0) {
      for (j = i * i; j < 1000001; j += i)
        b[j] = 1;
    }
  }
  vector<ll> v(1000001, 0);
  set<ll> st;
  for (i = 2; i < 1000001; i++)
    if (b[i] == 0)
      st.insert(i);

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

  ll ans = gcd(a[0], a[1]);
  set<ll>::iterator it;
  for (i = 2; i < n; i++)
    if (ans != 1)
      ans = gcd(ans, a[i]);

  if (ans > 1)
    cout << "not coprime";
  else {
    sort(a, a + n);
    for (i = 0; i < n; i++) {
      for (it = st.begin(); it != st.end(); it++) {
        ll c = (*it);
        if (a[i] % c == 0) {
          v[c]++;
          if (v[c] > 1) {
            cout << "setwise coprime";
            exit(0);
          }
          st.erase(c);
        }

        while (a[i] % c == 0)
          a[i] /= c;
        if (a[i] == 1)
          break;
      }
      if (a[i] != 1) {
        cout << "setwise coprime";
        exit(0);
      }
    }
    cout << "pairwise coprime";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  fastio ll n, t, i, j, x, k;
  cin >> n;
  ll b[1000001] = {0};

  for (i = 2; i * i < 1000001; i++) {
    if (b[i] == 0) {
      for (j = i * i; j < 1000001; j += i)
        b[j] = 1;
    }
  }
  vector<ll> pr, v(1000001, 0);
  for (i = 2; i < 1000001; i++)
    if (b[i] == 0)
      pr.push_back(i);

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

  ll ans = gcd(a[0], a[1]);

  for (i = 2; i < n; i++)
    ans = gcd(ans, a[i]);

  if (ans > 1)
    cout << "not coprime";
  else {
    x = 1;

    for (i = 0; i < n; i++) {
      for (j = 0; j < pr.size(); j++) {
        if (a[i] % pr[j] == 0) {
          v[pr[j]]++;
          if (v[pr[j]] > 1)
            x = -1;
        }
        if (x == -1) {
          cout << "setwise coprime";
          exit(0);
        }
        while (a[i] % pr[j] == 0)
          a[i] /= pr[j];
        if (a[i] == 1)
          break;
      }
    }
    cout << "pairwise coprime";
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//__uint128_t
const ll MOD = 1e9 + 7;

vector<ll> D(1e6 + 5, 1);
vector<ll> Eratosthenes(ll N) {
  vector<bool> is_prime(N + 1, true);
  vector<ll> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      D[i] = i;
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
        D[j] = i;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

int main() {

  ll N;
  cin >> N;
  vector<ll> V(N);
  for (int i = 0; i < N; i++)
    cin >> V[i];
  vector<ll> P = Eratosthenes(1e6);
  map<ll, ll> M;
  for (int i = 0; i < N; i++) {
    ll x = V[i];
    set<ll> ST;
    while (x != 1) {
      ll p = D[x];
      ST.insert(p);
      x = x / p;
    }
    for (auto st : ST)
      M[st]++;
  }
  ll cnt = 0;
  for (auto m : M)
    cnt = max(cnt, m.second);
  if (cnt == N)
    cout << "not coprime" << endl;
  else if (cnt >= 2)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//__uint128_t
const ll MOD = 1e9 + 7;

vector<ll> Eratosthenes(ll N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++)
    is_prime[i] = true;
  vector<ll> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i)
        is_prime[j] = false;
      P.emplace_back(i);
    }
  }
  return P;
}

int main() {

  ll N;
  cin >> N;
  vector<ll> V(N);
  for (int i = 0; i < N; i++)
    cin >> V[i];
  vector<ll> P = Eratosthenes(1e6);
  unordered_map<ll, ll> M;
  for (auto x : V) {
    for (auto p : P) {
      if (x % p == 0)
        M[p]++;
    }
  }
  ll cnt = 0;
  for (auto m : M) {
    cnt = max(cnt, m.second);
  }

  if (cnt == N)
    cout << "not coprime" << endl;
  else if (cnt >= 2)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define endl '\\n'
#define fd(n) fixed << setprecision(n)
#define MAX 100000000000000000
#define MAXN 1000050
#define mod 1000000007
#define pi 3.1415926535897932384626433

ll fun(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      ans = ans * 1ll * x;
      ans = ans % mod;
    }
    y = y / 2;
    x = (x * 1ll * x) % mod;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, i, flag = 0, j, x;
  ll prime[MAXN], prime1[MAXN];
  memset(prime, 0, sizeof(prime));
  memset(prime1, 0, sizeof(prime1));
  for (i = 2; i < MAXN; i++) {
    if (prime[i] == 0) {
      for (j = i + i; j < MAXN; j += i) {
        prime[j] = 1;
      }
    }
  }
  cin >> n;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    prime1[a[i]]++;
  }
  x = a[0];
  for (i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x >= 2) {
    cout << "not coprime";
  } else {
    ll count = 0;
    for (i = 2; i < MAXN; i++) {
      count = 0;
      for (j = i; j < MAXN; j += i) {
        count += prime1[j];
      }
      if (count > 1) {
        flag = 1;
      }
    }
    if (flag == 0) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  }
}

Error: WA

Fixed submission:

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define endl '\\n'
#define fd(n) fixed << setprecision(n)
#define MAX 100000000000000000
#define MAXN 100050
#define mod 1000000007
#define pi 3.1415926535897932384626433

ll fun(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      ans = ans * 1ll * x;
      ans = ans % mod;
    }
    y = y / 2;
    x = (x * 1ll * x) % mod;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, i, flag = 0, j, x;
  ll prime[MAXN], prime1[MAXN];
  memset(prime, 0, sizeof(prime));
  memset(prime1, 0, sizeof(prime1));
  for (i = 2; i < MAXN; i++) {
    if (prime[i] == 0) {
      for (j = i + i; j < MAXN; j += i) {
        prime[j] = 1;
      }
    }
  }
  cin >> n;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    prime1[a[i]]++;
  }
  x = a[0];
  for (i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x >= 2) {
    cout << "not coprime";
  } else {
    ll count = 0;
    for (i = 2; i < MAXN; i++) {
      count = 0;
      for (j = i; j < MAXN; j += i) {
        count += prime1[j];
      }
      if (count > 1) {
        flag = 1;
      }
    }
    if (flag == 0) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
const int MAXN = 1e6 + 50;
int a[MAXN];
int cnt[MAXN];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int t = 0;
  for (int i = 0; i < n; i++) {
    t = __gcd(t, a[i]);
    ++cnt[a[i]];
  }
  if (t > 1) {
    cout << "not coprime";
    return 0;
  }

  for (int i = 2; i < MAXN;
       i++) { // 1e6以内质数不到8w个，故这种暴力找倍数的方式没炸
    int num = 0;
    for (int j = i; j < MAXN; j += i)
      num += cnt[j];
    if (num > 1) {
      cout << "setwise coprime";
      return 0;
    }
  }
  cout << "pairwise coprime";

  return 0;
}


Error: WA

Fixed submission:

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

int a[100005];
bool p = true;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int t = a[0];
  for (int i = 1; i < n; i++) {
    t = __gcd(t, a[i]);
    if (t != 1)
      p = false;
  }
  int k = t;

  if (t == 1 && p) {
    cout << "pairwise coprime";
  } else if (k == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";

  return 0;
}