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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}

int n;
int ett[1001];
vector<int> p;
map<int, int> mp;

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

  for (int i = 2; i <= 1000; i++) {
    if (ett[i])
      continue;
    for (int j = i + i; j <= 1000; j += i)
      ett[j] = 1;
  }

  for (int i = 2; i <= 1000; i++) {
    if (!ett[i])
      p.push_back(i);
  }

  int g = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    g = gcd(g, a);

    int ta = a;
    for (int j : p) {
      if (a % j)
        continue;
      mp[j]++;

      while (a % j == 0)
        a /= j;
    }

    if (a != 1)
      mp[a]++;
  }

  if (g != 1) {
    cout << "not coprime";
  } else {
    bool flag = 0;
    for (auto it : mp) {
      if (it.second > 1)
        flag = 1;
    }

    if (flag)
      cout << "setwise coprime";
    else
      cout << "pairwise coprime";
  }
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}

int n;
map<int, int> mp;

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

  int g = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    g = gcd(g, a);

    int ta = a;
    for (int j = 2; j * j <= ta; j++) {
      if (a % j)
        continue;
      mp[j]++;

      while (a % j == 0)
        a /= j;
    }

    if (a != 1)
      mp[a]++;
  }

  if (g != 1) {
    cout << "not coprime";
  } else {
    bool flag = 0;
    for (auto it : mp) {
      if (it.second > 1)
        flag = 1;
    }

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

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

int primes[1000001];

void spf() {
  for (int i = 2; i <= 1000000; ++i) {
    if (!primes[i]) {
      for (int j = i; j <= 1000000; j += i) {
        if (!primes[j])
          primes[j] = i;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  spf();
  // for(int i=1;i<=1000000;++i) if(primes[i] == 0) cout << i << ' ' <<
  // primes[i] << '\\n'; cout << "res\\n";
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  int seen[1000001] = {0};
  vector<int> nums;
  for (int i = 0; i < n; ++i) {
    int val = vec[i];
    set<int> current;
    while (val > 1) {
      int factor = primes[val];
      current.insert(factor);
      val /= factor;
    }
    for (int i : current)
      seen[i] += 1;
  }
  bool pairwise = true;
  bool notprime = false;

  for (int i = 1; i <= 1000000; ++i) {

    if (seen[i] > 1)
      pairwise = false;
    if (seen[i] == n)
      notprime = true;
  }

  if (notprime)
    cout << "not coprime\\n";
  else if (pairwise)
    cout << "pairwise coprime\\n";
  else
    cout << "setwise coprime\\n";

  return 0;
}

Error: 0

Fixed submission:

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

int primes[1000001];

void spf() {
  for (int i = 2; i * i <= 1000000; ++i) {
    if (!primes[i]) {
      for (int j = i; j <= 1000000; j += i) {
        primes[j] = i;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  spf();
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }

  int seen[1000001] = {0};
  vector<int> nums;
  for (int i = 0; i < n; ++i) {
    int val = vec[i];
    set<int> current;
    while (val > 1) {
      int factor = primes[val];
      current.insert(factor);
      val /= factor;
    }
    for (int i : current)
      seen[i] += 1;
  }
  bool pairwise = true;
  bool notprime = false;

  for (int i = 1; i <= 1000000; ++i) {

    if (seen[i] > 1)
      pairwise = false;
    if (seen[i] == n)
      notprime = true;
  }

  if (notprime)
    cout << "not coprime\\n";
  else if (pairwise)
    cout << "pairwise coprime\\n";
  else
    cout << "setwise coprime\\n";

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

/*
Problem Number: ABC177E
Problem Name: Coprime
Notes:
*/

#include <bits/stdc++.h>
#define endl "\\n"
#define ll long long

using namespace std;

int sp[int(1e6) + 1];

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

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

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

  memset(sp, 0, sizeof(sp));
  for (int i = 2; i < int(1e6) + 1; i++)
    if (!sp[i])
      for (int j = i; j < int(1e6) + 1; j += i)
        if (!sp[j])
          sp[j] = i;

  bool primes[int(1e6)];
  memset(primes, 0, sizeof(primes));
  for (int i = 0; i < n; i++) {
    int ai = a[i];
    while (ai != 1) {
      int spi = sp[ai];
      if (primes[spi]) {
        cout << "setwise coprime" << endl;
        return 0;
      }
      primes[spi] = 1;
      while (ai % spi == 0)
        ai /= spi;
    }
  }

  cout << "pairwise coprime" << endl;

  return 0;
}

Error: TLE

Fixed submission:

/*
Problem Number: ABC177E
Problem Name: Coprime
Notes:
*/

#include <bits/stdc++.h>
#define endl "\\n"
#define ll long long

using namespace std;

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

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

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

  bool primes[int(1e6)];
  memset(primes, 0, sizeof(primes));
  for (int i = 0; i < n; i++) {
    for (int j = 2, ai = a[i]; j <= a[i] && ai != 1; j++)
      if (ai % j == 0) {
        if (primes[j]) {
          cout << "setwise coprime" << endl;
          return 0;
        }
        primes[j] = 1;
        while (ai % j == 0)
          ai /= j;
      }
  }

  cout << "pairwise coprime" << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const long long INF = 1e15;

const int Max = 1e7;
vector<int> mps(Max + 1);

void mpsinit() { // O(NloglogN)
  for (int i = 0; i <= Max; i++)
    mps[i] = i;
  for (ll i = 2; i * i <= Max; i++) {
    if (mps[i] == i) {
      for (ll j = i * i; j <= Max; j += i) {
        if (mps[j] == j)
          mps[j] = i;
      }
    }
  }
}
template <typename T> set<T> prime_factorization(T n) { // O(logN)
  set<T> ret;
  while (mps[n] != n) {
    ret.insert(mps[n]);
    n = n / mps[n];
  }
  ret.insert(mps[n]);
  return ret;
}

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

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

  mpsinit();
  map<int, bool> seen;
  bool pc = true;

  for (int i = 0; i < n; i++) {
    if (a[i] == 1)
      continue;
    set<int> fp = prime_factorization(a[i]);
    for (auto p : fp) {
      if (seen[p])
        pc = false;
      seen[p] = true;
    }
  }

  int g = __gcd(a[0], a[1]);
  for (int i = 0; i < n; i++)
    g = __gcd(g, a[i]);

  if (pc)
    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 ll mod = 1e9 + 7;
const long long INF = 1e15;

// ユークリッドの互除法
ll gcd(ll x, ll y) {
  if (x > y)
    swap(x, y);
  if (x == 0)
    return y;
  return gcd(x, y % x);
}

vector<bool> flag_prime(ll max) {
  vector<bool> flag(max, true);

  flag[0] = false;
  flag[1] = false;
  for (int i = 2; i * i < max + 1; i++) {
    if (flag[i]) {
      for (int j = 2; i * j < max + 1; j++)
        flag[i * j] = false;
    }
  }

  return flag;
}

vector<int> num_prime(int max) {
  vector<int> num;
  vector<bool> flag = flag_prime(max);

  for (int i = 0; i < max + 1; i++) {
    if (flag[i])
      num.push_back(i);
  }
  return num;
}

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

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

  bool pc = true;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      if (gcd(a[i], a[j]) != 1) {
        pc = false;
        break;
      }
    }
  }

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

  int g = gcd(a[0], a[1]);
  for (int i = 0; i < n; i++)
    g = gcd(g, a[i]);

  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

void div(long long N, vector<ll> &num) {
  for (long long i = 2; i * i <= N; ++i) {
    if (N % i != 0)
      continue;
    while (N % i == 0) {
      N /= i;
    }
    num[i]++;
  }
  if (N != 1)
    num[N]++;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<ll> num(1e6 + 10, 0);
  for (ll i = 0; i < n; i++) {
    div(a[i], num);
  }
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  ll judge = num[0];
  if (judge >= n)
    cout << "not coprime" << endl;
  else if (judge > 1)
    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 ll MOD = 1e9 + 7;

vector<long long> enum_divisors(long long N) {
  vector<long long> res;
  for (long long i = 2; i * i <= N; ++i) {
    if (N % i != 0)
      continue;
    while (N % i == 0) {
      N /= i;
    }
    res.push_back(i);
  }
  if (N != 1)
    res.push_back(N);
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<ll>> num(n);
  map<ll, ll> mp;
  for (ll i = 0; i < n; i++) {
    num[i] = enum_divisors(a[i]);
    for (ll x : num[i]) {
      mp[x]++;
    }
  }
  bool ok1 = true, ok2 = true;
  for (auto x : mp) {
    ll judge = x.second;
    if (judge > 1)
      ok1 = false;
    if (judge >= n)
      ok2 = false;
  }
  if (ok1)
    cout << "pairwise coprime" << endl;
  else if (ok2)
    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;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  // pairwise coprime
  bool p = true;
  sort(a.begin(), a.end());
  // A_i = 1 (1 <= i <= n)
  if (a[n - 1] == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  set<int> prime;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1)
      continue;
    int j = 2;
    if (prime.find(a[i]) != prime.end()) {
      p = false;
      goto END_REP;
    }
    prime.insert(a[i]);
    while (j * j <= a[i]) {
      if (a[i] % j == 0) {
        int q = a[i] / j;
        if (prime.find(j) != prime.end() || prime.find(q) != prime.end()) {
          p = false;
          goto END_REP;
        } else {
          prime.insert(j);
          prime.insert(q);
        }
      }
      j++;
    }
  }
END_REP:;
  // for(int i : prime)
  //     cout << i << endl;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  // pairwise coprime
  bool p = true;
  sort(a.begin(), a.end());
  // A_i = 1 (1 <= i <= n)
  if (a[n - 1] == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  set<int> prime;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1)
      continue;
    int j = 2;
    if (prime.find(a[i]) != prime.end()) {
      p = false;
      // goto END_REP;
    }
    prime.insert(a[i]);
    while (j * j <= a[i]) {
      if (a[i] % j == 0) {
        int q = a[i] / j;
        if (prime.find(j) != prime.end() || prime.find(q) != prime.end()) {
          p = false;
          // goto END_REP;
        } else {
          prime.insert(j);
          prime.insert(q);
        }
      }
      j++;
    }
  }
  // END_REP: ;
  //  for(int i : prime)
  //      cout << i << endl;

  if (p)
    cout << "pairwise coprime" << endl;
  else {
    // setwise coprime
    int g = a[0];
    for (int i = 1; i < n; i++)
      g = gcd(g, a[i]);
    if (g == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<ll> sieve(1000005, 0);
vector<ll> fsctor(ll n) {
  vector<ll> res;
  while (n > 1) {
    res.push_back(sieve[n]);
    n /= sieve[n];
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  iota(sieve.begin(), sieve.end(), 0);
  for (ll i = 2; i * i < 1000005; i++) {
    if (sieve[i] < i)
      continue;
    for (ll j = i * i; j < 1000005; j += i)
      if (sieve[j] == j)
        sieve[j] = i;
  }

  vector<ll> a(n);
  for (auto &i : a)
    cin >> i;
  vector<map<int, int>> vm(n);
  vector<vector<ll>> a_primes(n);
  bool isparwize = true;
  for (int i = 0; i < n; i++) {
    auto now = fsctor(a[i]);
    now.erase(unique(now.begin(), now.end()), now.end());
    a_primes[i] = now;

    for (auto j : now) {
      vm[0][j]++;
      if (vm[0][j] > 1) {
        isparwize = false;
      }
    }
  }
  vector<ll> prime;
  if (isparwize) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll GCD = a[0];
  for (int i = 0; i < n; i++) {
    GCD = __gcd(GCD, a[i]);
  }
  if (GCD == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: TLE

Fixed submission:

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

vector<ll> fsctor(int n, const vector<ll> &min_factor) {
  vector<ll> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  vector<ll> sieve(1000005, 0);
  iota(sieve.begin(), sieve.end(), 0);
  for (ll i = 2; i * i < 1000005; i++) {
    if (sieve[i] < i)
      continue;
    for (ll j = i * i; j < 1000005; j += i)
      if (sieve[j] == j)
        sieve[j] = i;
  }

  vector<ll> a(n);
  for (auto &i : a)
    cin >> i;
  vector<map<int, int>> vm(n);
  for (int i = 0; i < n; i++) {
    auto now = fsctor(a[i], sieve);
    for (auto j : now)
      vm[i][j]++;
  }
  vector<ll> prime;
  for (int i = 2; i < 1000005; i++) {
    if (sieve[i] == i)
      prime.push_back(i);
  }
  bool isparwize = true;
  for (int i = 0; i < n; i++) {
    bool tow = false;
    for (auto j : prime) {

      if (vm[i].count(j)) {
        if (tow)
          isparwize = false;
        tow = true;
      }
    }
  }
  if (isparwize) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll GCD = a[0];
  for (int i = 0; i < n; i++) {
    GCD = __gcd(GCD, a[i]);
  }
  if (GCD == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

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

  map<ll, ll> m;

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

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll x = a[i];

    for (ll j = 2; j * j <= x; j++) {

      if ((x % j) == 0) {
        if (m[j] == 0) {
          m[j]++;
        } else {
          ans++;
          break;
        }
        while ((x % j == 0)) {
          x /= j;
        }
      }
    }
    if (ans == 0 && x != 1) {
      if (m[x] >= 1) {
        ans++;
        break;
      } else {
        m[x]++;
      }
    }
    if (ans == 1) {
      break;
    }
  }

  ll g = a[0];
  for (ll i = 0; i < n; i++) {
    g = __gcd(g, a[i]);
  }
  if (g != 1) {
    ans++;
  }
  if (ans == 0) {
    cout << "pairwise coprime" << endl;
  } else if (ans == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}


Error: -8

Fixed submission:

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

int main() {

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

  map<ll, ll> m;

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

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll x = a[i];

    for (ll j = 2; j * j <= x; j += 2) {

      if (x % 2 == 0) {
        m[2]++;
        if (m[2] > 1) {
          ans++;
          break;
        }
      }

      while (x % 2 == 0) {
        x /= 2;
      }

      if ((x % j) == 0) {
        m[j]++;
      }
      ll k = x / j;
      if ((x % k) == 0) {
        m[k]++;
      }
      if (m[j] > 1 || m[k] > 1) {
        ans++;
        break;
      }
    }

    if (ans == 1) {
      break;
    }
  }

  ll g = a[0];
  for (ll i = 0; i < n; i++) {
    g = __gcd(g, a[i]);
  }
  if (g != 1) {
    ans++;
  }
  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, verdict: Runtime Error

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

const int MAXN = 1e6 + 5;
const int MOD = 1e9 + 7;

int n, a[MAXN], cnt[MAXN], gcdd;
vector<int> v[MAXN];

template <class T> void read(T &x, T f = 1, char ch = getchar()) {
  x = 0;
  while (ch < '0' || ch > '9')
    f = (ch == '-' ? -1 : 1), ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - 48, ch = getchar();
  x *= f;
}

bool isprime(int x) {
  for (int i = 2; i <= sqrt(x); i++)
    if (x % i == 0)
      return false;
  return true;
}

void init() {
  for (int i = 2; i <= 1000000; i++) {
    if (isprime(i)) {
      for (int k = 1; k * i <= 1000000; k++)
        v[k * i].push_back(i);
    }
  }
}

int main() {
  init();
  read(n);
  for (int i = 1; i <= n; i++)
    read(a[i]);
  gcdd = a[1];
  for (int i = 2; i <= n; i++)
    gcdd = __gcd(a[i], gcdd);
  bool tag = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < v[a[i]].size(); j++)
      if (cnt[v[a[i]][j]]) {
        tag = 0;
        break;
      }
    for (int j = 0; j < v[a[i]].size(); j++)
      cnt[v[a[i]][j]]++;
  }
  if (tag)
    cout << "pairwise coprime";
  else {
    if (gcdd == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  }
  return 0;
}


Error: WA

Fixed submission:

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

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;

int n, a[MAXN], cnt[MAXN], gcdd;
vector<int> v[MAXN];

template <class T> void read(T &x, T f = 1, char ch = getchar()) {
  x = 0;
  while (ch < '0' || ch > '9')
    f = (ch == '-' ? -1 : 1), ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - 48, ch = getchar();
  x *= f;
}

bool isprime(int x) {
  for (int i = 2; i <= sqrt(x); i++)
    if (x % i == 0)
      return false;
  return true;
}

void init() {
  for (int i = 2; i <= 1000; i++) {
    if (isprime(i) || i == 2) {
      for (int k = 1; k * i <= 100000; k++)
        v[k * i].push_back(i);
    }
  }
}

int main() {
  init();
  read(n);
  for (int i = 1; i <= n; i++)
    read(a[i]);
  gcdd = a[1];
  for (int i = 2; i <= n; i++)
    gcdd = __gcd(a[i], gcdd);
  bool tag = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < v[a[i]].size(); j++)
      if (cnt[v[a[i]][j]]) {
        tag = 0;
        break;
      }
    for (int j = 0; j < v[a[i]].size(); j++)
      cnt[v[a[i]][j]]++;
  }
  if (tag)
    cout << "pairwise coprime";
  else {
    if (gcdd == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long int
#define All(a) (a).begin(), (a).end()

vector<int> X(1000001);

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

void solve() {
  int n, m;
  scanf("%d", &n);
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    X[A[i]]++;
  }
  sort(All(A));

  int tmp = A[0];
  for (int i = 1; i < n; i++) {
    tmp = gcd(tmp, A[i]);
  }
  if (tmp > 1) {
    printf("not coprime\\n");
    return;
  }

  for (int i = 2; i < 1000001; i++) {
    int cnt = 0;
    for (int j = i; j < 1000001; j += i) {
      cnt += X[j];
    }
    if (cnt > 1) {
      printf("setwise coprime\\n");
      return;
    }
    // auto a=find(All(X),f[j]);
    // if(a!=X.end())goto setwise;
    // else{
    // X.push_back(f[j]);
    // }
  }
  printf("pairwise coprime\\n");
  return;
}
int main() {

  // int q=3;
  // while(q--){
  //   solve();
  // }
  solve();
  return 0;
}

Error: -11

Fixed submission:

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

#define ll long long int
#define All(a) (a).begin(), (a).end()

vector<int> X(1000001);

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

void solve() {
  int n, m;
  vector<int> X;
  scanf("%d", &n);
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    X[A[i]]++;
  }
  sort(All(A));

  int tmp = A[0];
  for (int i = 1; i < n; i++) {
    tmp = gcd(tmp, A[i]);
  }
  if (tmp > 1) {
    printf("not coprime\\n");
    return;
  }

  for (int i = 2; i < 1000001; i++) {
    int cnt = 0;
    for (int j = i; j < 1000001; j += i) {
      cnt += X[i];
    }
    if (cnt > 1) {
      printf("setwise coprime\\n");
      return;
    }
    // auto a=find(All(X),f[j]);
    // if(a!=X.end())goto setwise;
    // else{
    // X.push_back(f[j]);
    // }
  }
  printf("pairwise coprime\\n");
  return;
}
int main() {

  // int q=3;
  // while(q--){
  //   solve();
  // }
  solve();
  return 0;
}