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

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MX = 1e6 + 5;

int n, A[MX];
bool ok = true;
set<int> found;

int main() {
  cin.tie(0)->sync_with_stdio(0);

  rep(i, 0, MX) A[i] = -1;
  rep(i, 2, MX) {
    if (A[i] == -1) {
      for (int j = i; j < MX; j += i) {
        if (A[j] == -1) {
          A[j] = i;
        }
      }
    }
  }

  cin >> n;
  int GCD;
  rep(i, 0, n) {
    int a;
    cin >> a;
    if (!i)
      GCD = a;
    else
      GCD = __gcd(GCD, a);
    set<int> tmp;
    while (a > 1) {
      tmp.insert(A[a]);
      a /= A[a];
    }
    for (auto j : tmp) {
      if (found.find(j) != found.end())
        ok = false;
      found.insert(j);
    }
  }

  if (ok)
    cout << "pairwise coprime";
  else if (GCD == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}


Error: TLE

Fixed submission:

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MX = 1e6;

int n;
bitset<MX> seen;

bitset<MX> val;
vector<int> primes;
void pre() {
  val.set();
  for (int i = 2; i <= 1e5; ++i) {
    if (val[i]) {
      primes.push_back(i);
      for (int j = i; j <= 1e5; j += i) {
        val[j] = false;
      }
    }
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  pre();
  seen.reset();
  bool pairwise = true;
  cin >> n;
  int gcd;
  rep(i, 0, n) {
    int a;
    cin >> a;
    int orig = a;
    set<int> tmp;
    rep(j, 0, sz(primes)) {
      int prime = primes[j];
      while (a % prime == 0) {
        tmp.insert(j);
        a /= prime;
      }
    }

    for (auto j : tmp) {
      if (seen[j]) {
        pairwise = false;
      }
      seen[j] = true;
    }

    if (!i)
      gcd = orig;
    else
      gcd = __gcd(gcd, orig);
  }

  if (pairwise)
    cout << "pairwise coprime";
  else if (gcd == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

std::vector<int> Eratosthenes(const int N) {
  std::vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<int> 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() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool ok1 = true, ok2 = true;
  // 2
  int g = __gcd(a[0], a[1]);
  rep(i, n) g = __gcd(g, a[i]);
  if (g != 1)
    ok2 = false;
  // 1
  set<int> se;
  vector<int> e = Eratosthenes(1000005);
  rep(i, n) {
    set<int> cnt;
    rep(j, e.size()) {
      if ((ll)e[j] * e[j] > a[i])
        break;
      while (a[i] % e[j] == 0) {
        a[i] /= e[j];
        cnt.insert(e[j]);
      }
    }
    if (a[i] != 1)
      cnt.insert(a[i]);
    for (auto &p : cnt) {
      if (se.find(p) != se.end())
        ok1 = false;
      se.insert(p);
    }
  }
  if (ok1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  if (ok2) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

std::vector<int> Eratosthenes(const int N) {
  std::vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<int> 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() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool ok1 = true, ok2 = true;
  // 2
  int g = __gcd(a[0], a[1]);
  rep(i, n) g = __gcd(g, a[i]);
  if (g != 1)
    ok2 = false;
  // 1
  set<int> se;
  vector<int> e = Eratosthenes(1000005);
  rep(i, n) {
    set<int> cnt;
    rep(j, e.size()) {
      while (a[i] % e[j] == 0) {
        a[i] /= e[j];
        cnt.insert(e[j]);
      }
    }
    if (a[i] != 1)
      cnt.insert(a[i]);
    for (auto &p : cnt) {
      if (se.find(p) != se.end())
        ok1 = false;
      se.insert(p);
    }
  }
  if (ok1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  if (ok2) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

  int n;
  cin >> n;

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

  ll g = a[0];
  rep(i, n - 1) g = mygcd(g, a[i + 1]);

  if (g > 1) {
    cout << "not coprime" << endl;
    exit(0);
  }

  int max_n = 5050;
  vector<bool> isprime(max_n, true);
  isprime[0] = isprime[1] = false;
  for (int i = 2; i < max_n; i++) {
    if (isprime[i]) {
      for (int j = 2 * i; j < max_n; j += i)
        isprime[j] = false;
    }
  }

  vector<int> primes;
  rep(i, max_n) if (isprime[i]) primes.push_back(i);

  set<int> stall;
  rep(i, n) {
    int t = a[i];
    set<int> st;
    for (int p : primes) {
      if (t % p == 0)
        st.insert(p);
      while (t % p == 0)
        t /= p;
    }

    if (t > 1)
      st.insert(t);

    for (int x : st) {
      if (stall.count(x) == 1) {
        cout << "setwise coprime" << endl;
        exit(0);
      }

      stall.insert(x);
    }
  }

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


Error: TLE

Fixed submission:

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

using namespace std;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

  int n;
  cin >> n;

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

  ll g = a[0];
  rep(i, n - 1) g = mygcd(g, a[i + 1]);

  if (g > 1) {
    cout << "not coprime" << endl;
    exit(0);
  }

  int max_n = 1010101;
  vector<bool> isprime(max_n, true);
  isprime[0] = isprime[1] = false;
  for (int i = 2; i < max_n; i++) {
    if (isprime[i]) {
      for (int j = 2 * i; j < max_n; j += i)
        isprime[j] = false;
    }
  }

  vector<int> primes;
  rep(i, max_n) if (isprime[i]) primes.push_back(i);

  set<int> stall;
  rep(i, n) {
    int t = a[i];
    set<int> st;
    for (int p : primes) {
      while (t % p == 0) {
        if (st.count(p) == 0)
          st.insert(p);
        t /= p;
      }
    }

    for (int x : st) {
      if (stall.count(x) == 1) {
        cout << "setwise coprime" << endl;
        exit(0);
      }

      stall.insert(x);
    }
  }

  cout << "pairwise coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define AC 0
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, gcd = 0;
  cin >> n;
  vector<int> a(n), prime(1e6 + 1);
  bool p = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int tmp = a[i];
    for (int j = 2; 1ll * j * j <= tmp; j++)
      if (!(tmp % j)) {
        if (prime[j])
          p = 0;
        prime[j] = 1;
        while (!(tmp % j))
          tmp /= j;
      }
    if (tmp != 1) {
      if (prime[tmp])
        p = 0;
      prime[tmp] = 1;
    }
    gcd = __gcd(gcd, a[i]);
  }
  if (p)
    cout << "pairwise coprime\\n";
  else if (gcd == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
  return AC;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define AC 0
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, gcd = 0;
  cin >> n;
  vector<int> a(n), prime(n);
  bool p = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int tmp = a[i];
    for (int j = 2; 1ll * j * j <= tmp; j++)
      if (!(tmp % j)) {
        if (prime[j])
          p = 0;
        prime[j] = 1;
        while (!(tmp % j))
          tmp /= j;
      }
    if (tmp != 1) {
      if (prime[tmp])
        p = 0;
      prime[tmp] = 1;
    }
    gcd = __gcd(gcd, a[i]);
  }
  if (p)
    cout << "pairwise coprime\\n";
  else if (gcd == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
  return AC;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int cnt[1000005], a[1000005];
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int main() {
  int n, f1 = 1;
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    int t = a[i];
    for (int j = 2; j * j <= t; j++) {
      if (t % j == 0) {
        while (t % j == 0)
          t /= j;
        cnt[j]++;
        if (cnt[i] > 1) {
          f1 = 0;
          break;
        }
      }
    }
    if (t > 1) {
      cnt[t]++;
      if (cnt[t] > 1) {
        f1 = 0;
        break;
      }
    }
    if (f1 == 0)
      break;
  }
  if (f1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int now = a[1];
  for (int i = 2; i <= n; i++)
    now = gcd(now, a[i]);
  if (now == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int cnt[100005], a[100005];
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int main() {
  int n, f1 = 1;
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    int 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]++;
  }
  for (int i = 2; i <= 100000; i++)
    if (cnt[i] > 1) {
      f1 = 0;
      break;
    }
  if (f1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int now = a[1];
  for (int i = 2; i <= n; i++)
    now = gcd(now, a[i]);
  if (now == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int mx = 0;
  vector<int> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
    mx = max(mx, nums[n]);
  }
  vector<int> mods(mx + 1);
  mods[1] = 1;
  for (int i = 2; i <= mx; ++i) {
    if (mods[i] != 0) {
      continue;
    }
    mods[i] = i;
    int tmp = i;
    while (tmp + i <= mx) {
      tmp += i;
      if (mods[tmp] != 0)
        continue;
      mods[tmp] = i;
    }
  }
  bitset<1000001> already;
  vector<int> cnts(mx + 1);
  bool pairwise = true;
  for (int n : nums) {
    while (n > 1) {
      int tmp = mods[n];
      while (n % tmp == 0) {
        n /= tmp;
      }
      if (already.test(tmp)) {
        pairwise = false;
      }
      if (++cnts[tmp] == N) {
        cout << "not coprime" << endl;
        return 0;
      }
      already.set(tmp);
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

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

  int mx = 0;
  vector<int> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
    mx = max(mx, nums[n]);
  }
  vector<int> mods(mx + 1);
  mods[1] = 1;
  for (int i = 2; i <= mx; ++i) {
    if (mods[i] != 0) {
      continue;
    }
    mods[i] = i;
    int tmp = i;
    while (tmp + i <= mx) {
      tmp += i;
      if (mods[tmp] != 0)
        continue;
      mods[tmp] = i;
    }
  }
  bitset<1000001> already;
  vector<int> cnts(mx + 1);
  bool pairwise = true;
  for (int n : nums) {
    bitset<1000001> cur;
    cur.set(n);
    ++cnts[n];
    while (n > 1) {
      int tmp = mods[n];
      while (n % tmp == 0) {
        n /= tmp;
      }
      if (pairwise && already.test(tmp)) {
        pairwise = false;
      }
      if (!cur.test(tmp)) {
        if (++cnts[tmp] == N) {
          cout << "not coprime" << endl;
          return 0;
        }
        cur.set(tmp);
      }
    }
    already |= cur;
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }

  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
#define X first
#define Y second
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int maxN = 1000000;
int n, a[maxN + 10], have[maxN + 10];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int isn[maxN + 10], prime[maxN + 10], len, GCD;
bool vis[maxN + 10];
void init() {
  for (int i = 2; i <= maxN; i++) {
    if (!vis[i])
      prime[++len] = i, isn[i] = i;
    for (int j = 1; j <= len; j++) {
      if (i * prime[j] > maxN)
        break;
      vis[i * prime[j]] = 1;
      isn[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
  //    for(int i=2;i<=100;i++)printf("%d %d\\n",i,isn[i]);
}

int main() {
  init();
  n = read();
  a[1] = read();
  GCD = a[1];
  for (int i = 2; i <= n; i++)
    a[i] = read(), GCD = gcd(GCD, a[i]);
  if (GCD != 1)
    return puts("not coprime"), 0;
  for (int i = 1; i <= n; i++) {
    int tmp = a[i];
    while (tmp > 1) {
      int h = isn[tmp];
      have[isn[tmp]]++;
      if (have[isn[tmp]] > 1)
        return puts("setwise coprime"), 0;
      while (isn[tmp] == h)
        tmp /= isn[tmp];
    }
  }
  puts("pairwise coprime");
  return 0;
}
/*

*/


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
#define X first
#define Y second
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int maxN = 100000;
int n, a[maxN + 10], have[maxN + 10];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int isn[maxN + 10], prime[maxN + 10], len, GCD;
bool vis[maxN + 10];
void init() {
  for (int i = 2; i <= maxN; i++) {
    if (!vis[i])
      prime[++len] = i, isn[i] = i;
    for (int j = 1; j <= len; j++) {
      if (i * prime[j] > maxN)
        break;
      vis[i * prime[j]] = 1;
      isn[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
  //    for(int i=2;i<=100;i++)printf("%d %d\\n",i,isn[i]);
}

int main() {
  init();
  n = read();
  a[1] = read();
  GCD = a[1];
  for (int i = 2; i <= n; i++)
    a[i] = read(), GCD = gcd(GCD, a[i]);
  if (GCD != 1)
    return puts("not coprime"), 0;
  for (int i = 1; i <= n; i++) {
    int tmp = a[i];
    while (tmp > 1) {
      int h = isn[tmp];
      have[isn[tmp]]++;
      if (have[isn[tmp]] > 1)
        return puts("setwise coprime"), 0;
      while (isn[tmp] == h)
        tmp /= isn[tmp];
    }
  }
  puts("pairwise coprime");
  return 0;
}
/*

*/
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define N int(1e6 + 10)
#define fi first
#define si second
#define pb push_back
using namespace std;
int spf[N];
int m[N];
vector<int> cm;
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < N; i++)
    spf[i] = i;

  for (int i = 4; i < N; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < N; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

int main() {
  int n;
  cin >> n;
  int a[n], g = 0;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  sieve();
  for (int i = 0, x; i < n; i++) {
    x = a[i];
    g = __gcd(g, a[i]);
    while (x > 1) {
      m[spf[x]]++;
      x /= spf[x];
    }
  }
  bool first = true;
  for (int i = 0, x; i < n && first; i++) {
    x = a[i];
    while (x > 1) {
      cm.pb(spf[x]);
      m[spf[x]]--;
      x /= spf[x];
    }
    for (int i = 0; i < cm.size(); i++)
      if (m[cm[i]]) {
        first = false;
      }
    for (int i = 0; i < cm.size(); i++)
      m[cm[i]]++;
    cm.clear();
  }
  if (first) {
    printf("pairwise coprime\\n");
  } else if (g == 1) {
    printf("setwise coprime\\n");
  } else
    printf("not coprime\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define N int(1e6 + 10)
#define fi first
#define si second
using namespace std;
int spf[N];
map<int, int> m, cm;
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < N; i++)
    spf[i] = i;

  for (int i = 4; i < N; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < N; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  sieve();
  int n;
  cin >> n;
  int a[n], g = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0, x; i < n; i++) {
    x = a[i];
    g = __gcd(g, a[i]);
    while (x > 1) {
      m[spf[x]]++;
      x /= spf[x];
    }
  }
  bool first = true;
  for (int i = 0, x; i < n && first; i++) {
    x = a[i];
    while (x > 1) {
      cm[spf[x]]++;
      x /= spf[x];
    }
    for (auto it : cm)
      if (it.si < m[it.fi]) {
        first = false;
      }
  }
  if (first) {
    cout << "pairwise coprime\\n";
  } else if (g == 1) {
    cout << "setwise coprime\\n";
  } else
    cout << "not coprime\\n";
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int n, x, num[1000005], ok = 1, g;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    ++num[x];
    g = gcd(x, g);
  }
  for (int i = 2; i <= 1000000; ++i) {
    int tot = 0;
    for (int j = i; j <= 1000000; j += i)
      tot += num[j];
    if (tot > 1) {
      ok = 0;
      break;
    }
  }
  if (ok)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}

Error: WA

Fixed submission:

#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
int n, x, num[1000005], pp = 1;
vector<int> v;
bool nprim[1000005];
int main() {
  cin >> n;
  for (int i = 2; i * i <= 1000000; ++i)
    if (!nprim[i])
      for (int j = i * i; j <= 1000000; j += i)
        nprim[j] = 1;
  for (int i = 2; i <= 1000000; ++i)
    if (!nprim[i])
      v.push_back(i);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    if (x == 1)
      continue;
    for (int j = 0; v[j] <= x; ++j)
      if (x % v[j] == 0) {
        ++num[v[j]];
        if (num[v[j]] > 1)
          pp = 0;
        if (num[v[j]] == n) {
          cout << "not coprime";
          return 0;
        }
      }
  }
  if (pp)
    cout << "pairwise coprime";
  else
    cout << "setwise coprime";
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int a, int b) {
  if (a > b)
    swap(a, b);
  while (b % a != 0) {
    int tmp = b % a;
    b = a;
    a = tmp;
  }
  return a;
}

int main() {
  int n, i, j, jud, t;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; ++i)
    cin >> a.at(i);
  vector<int> e(1e6 + 1);
  vector<int> d(1e6 + 1);
  for (i = 2; i * i <= 1e6; ++i) {
    if (e.at(i) == 1)
      continue;
    for (j = i; j <= 1e6; j += i) {
      e.at(j) = 1;
      d.at(j) = i;
    }
  }
  jud = a.at(0);
  for (i = 1; i < n; ++i)
    jud = gcd(jud, a.at(i));
  if (jud > 1)
    cout << "not coprime" << endl;
  else {
    map<int, pair<int, int>> mp;
    for (i = 0; i < n; ++i) {
      t = a.at(i);
      while (t != 1) {
        if (e.at(t) == 0)
          d.at(t) = t;
        if (mp[d.at(t)].first != i && mp[d.at(t)].second == 1) {
          cout << "setwise coprime" << endl;
          return 0;
        }
        mp[d.at(t)] = {i, 1};
        t /= d.at(t);
      }
    }
    cout << "pairwise coprime" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int gcd(int a, int b) {
  if (a > b)
    swap(a, b);
  while (b % a != 0) {
    int tmp = b % a;
    b = a;
    a = tmp;
  }
  return a;
}

int main() {
  int n, i, j, jud, t;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; ++i)
    cin >> a.at(i);
  vector<int> e(1e6 + 1);
  vector<int> d(1e6 + 1);
  for (i = 2; i * i <= 1e6; ++i) {
    if (e.at(i) == 1)
      continue;
    for (j = i; j <= 1e6; j += j) {
      e.at(j) = 1;
      d.at(j) = i;
    }
  }
  jud = a.at(0);
  for (i = 1; i < n; ++i)
    jud = gcd(jud, a.at(i));
  if (jud > 1)
    cout << "not coprime" << endl;
  else {
    map<int, pair<int, int>> mp;
    for (i = 0; i < n; ++i) {
      t = a.at(i);
      while (t != 1) {
        if (mp[d.at(t)].first != i && mp[d.at(t)].second == 1) {
          cout << "setwise coprime" << endl;
          return 0;
        }
        mp[d.at(t)] = {i, 1};
        t /= d.at(t);
      }
    }
    cout << "pairwise coprime" << endl;
  }
  return 0;
}