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

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

int n, a[1000005], cnt[1000005], cnt2[1000005];
bool can[1000005];
inline int read() {
  int s = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * w;
}

int main() {
  n = read();
  for (register int i = 1; i <= n; i++)
    a[i] = read(), can[i] = cnt2[a[i]] == 0, cnt2[a[i]]++;
  for (register int i = 1; i <= n; i++)
    if (can[i])
      for (register int j = 1; j * j <= a[i]; j++)
        if (a[i] % j == 0) {
          int num1 = j, num2 = a[i] / j, num3 = cnt2[a[i]];
          cnt[num1] += num3, cnt[num2] += num3;
          if (num1 == num2)
            cnt[num1] -= num3;
        }
  bool f = true;
  for (register int i = 2; i <= 1000000; i++) {
    if (cnt[i] == n) {
      printf("not coprime\\n");
      return 0;
    }
    f &= (cnt[i] == 1 || cnt[i] == 0);
  }
  if (f)
    printf("pairwise coprime\\n");
  else
    printf("setwise coprime\\n");
  return 0;
}

Error: TLE

Fixed submission:

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

int n, a[1000005], cnt[1000005];
inline int read() {
  int s = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * w;
}

int main() {
  n = read();
  for (register int i = 1; i <= n; i++)
    a[i] = read();
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j * j <= a[i]; j++)
      if (a[i] % j == 0) {
        int num1 = j, num2 = a[i] / j;
        cnt[num1]++, cnt[num2]++;
        if (num1 == num2)
          cnt[num1]--;
      }
  bool f = true;
  for (register int i = 2; i <= 1000000; i++) {
    if (cnt[i] == n) {
      printf("not coprime\\n");
      return 0;
    }
    f &= (cnt[i] == 1 || cnt[i] == 0);
  }
  if (f)
    printf("pairwise 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;
using ll = long long;
typedef pair<int, int> P;
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void coY() { cout << "Yes" << endl; }
void coN() { cout << "No" << endl; }

// Write From this Line

// const ll mod = 1e9+7;
// const ll mod = 998244353;
const int A = 1000005;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(A);
  rep(i, n) {
    cin >> a[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;
  rep(i, n) g = __gcd(g, a[i]);
  if (g == 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;
typedef pair<int, int> P;
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void coY() { cout << "Yes" << endl; }
void coN() { cout << "No" << endl; }

// Write From this Line

// const ll mod = 1e9+7;
// const ll mod = 998244353;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> check(2 * 1000000, 0);
  set<int> s;
  bool flag = 1;
  auto kesu = [&](int i) {
    if (s.count(i))
      return;
    for (int j = i; j < 2 * 1000000; j += i) {
      check[j] = 1;
    }
  };
  rep(i, n) {
    // 数を素因数分解する
    int N = a[i];
    if (check[N] == 1)
      flag = 0;
    if (s.count(N))
      continue;
    for (int j = 2; j * j < N; j++) {
      if (N % j == 0) {
        N /= j;
        kesu(j);
        //		if(s.count(j)){
        //			continue;
        //		} else {
        //			// j の倍数を消す
        //		}
      }
    }
    if (N != 1) {
      if (s.count(N))
        continue;
      else {
        kesu(N);
      }
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
  } else {
    int G = 0;
    rep(i, n) { G = __gcd(G, a[i]); }
    if (G == 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;
#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;
}

Error: TLE

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++) {
    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;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N = 1e6 + 1;
  ll n;
  cin >> n;
  vector<ll> v(n), f(N);
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
    f[v[i]]++;
  }
  bool flag = true;
  for (ll i = 2; i < N; i++) {
    ll cnt = 0;
    for (ll j = i; j < N; j += i) {
      cnt += f[j];
    }
    if (cnt > 1) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll ans = v[0];
  for (ll i = 1; i < n; i++) {
    ans = __gcd(ans, v[i]);
  }
  if (ans == 1) {
    cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N = 1e8 + 1;
  map<ll, bool> prime;
  for (ll i = 2; i * i < N; i++) {
    if (prime.count(i) == 0) {
      prime[i] = true;
      for (ll j = i * i; j < N; j += i)
        prime[j] = false;
    }
  }
  map<ll, map<ll, ll>> ap;
  for (ll i = 2; i * i < N; i++) {
    if (prime[i]) {
      for (ll j = i; j < N; j += i) {
        ap[j][i]++;
      }
    }
  }
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i];
  map<ll, ll> freq;
  bool flag = true;
  for (ll i = 0; i < n; i++) {
    if (v[i] == 1)
      continue;
    ll val = v[i];
    for (auto j : ap[val]) {
      if (freq.count(j.first)) {
        flag = false;
        break;
      }
      freq[j.first]++;
    }
    if (!flag)
      break;
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll ans = v[0];
  for (ll i = 1; i < n; i++) {
    ans = __gcd(ans, v[i]);
  }
  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;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
ll mod = 1000000007;
ll NMAX = 1000007;

ll gcd(ll a, ll b) {
  ll r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

vector<ll> eratosthenes(ll n) {
  vector<ll> list(n + 1, 1);
  for (ll i = 0; i <= n; i++) {
    list.at(i) = 1;
  }
  ll upper = ceil(sqrt(n));
  for (ll i = 2; i <= upper; i++) {
    if (list.at(i) == 1) {
      list.at(i) = i;
      ll cnt = 2 * i;
      while (cnt <= n) {
        if (list.at(cnt) == 1) {
          list.at(cnt) = i;
        }
        cnt += i;
      }
    }
  }

  return (list);
}

int main() {
  ll n;
  vector<ll> a(NMAX);
  const vector<ll> list = eratosthenes(NMAX);
  cin >> n;
  // c[i]:数列aの中でiが出現した回数
  vector<ll> c(NMAX, 0);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

  if (n == 2) {
    if (gcd(a[0], a[1]) != 1) {
      cout << "not coprime" << endl;
    } else {
      cout << "pairwise coprime" << endl;
    }
    return (0);
  }

  bool pairwise = true;
  for (ll i = 2; i < NMAX; i++) {
    ll cnt = 0;
    // iの倍数が何回現れるか
    for (ll j = i; j < NMAX; j += i) {
      cnt += c[j];
    }
    if (cnt > 1)
      pairwise = false;
  }

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

  ll g = gcd(a[0], a[1]);
  // cout << g << endl;

  for (ll i = 2; i < n; i++) {
    g = gcd(a[i], g);
    // cout << g << endl;
  }

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

  return (0);
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
ll mod = 1000000007;
ll NMAX = 1000007;

ll gcd(ll a, ll b) {
  ll r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

vector<ll> eratosthenes(ll n) {
  vector<ll> list(n + 1, 1);
  for (ll i = 0; i <= n; i++) {
    list.at(i) = 1;
  }
  ll upper = ceil(sqrt(n));
  for (ll i = 2; i <= upper; i++) {
    if (list.at(i) == 1) {
      list.at(i) = i;
      ll cnt = 2 * i;
      while (cnt <= n) {
        if (list.at(cnt) == 1) {
          list.at(cnt) = i;
        }
        cnt += i;
      }
    }
  }

  return (list);
}

int main() {
  ll n;
  vector<ll> a(NMAX);
  const vector<ll> list = eratosthenes(NMAX);
  cin >> n;
  rep(i, n) { cin >> a[i]; }

  if (n == 2) {
    if (gcd(a[0], a[1]) != 1) {
      cout << "not coprime" << endl;
    } else {
      cout << "pairwise coprime" << endl;
    }
    return (0);
  }

  bool pairwise = true;

  rep(i, ceil(sqrt(NMAX))) {
    ll cnt = 0;
    rep(j, n) {
      if (a[j] % i == 0)
        cnt++;
    }
    if (cnt > 1)
      pairwise = false;
  }

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

  ll g = gcd(a[0], a[1]);
  // cout << g << endl;

  for (ll i = 2; i < n; i++) {
    g = gcd(a[i], g);
    // cout << g << endl;
  }

  if (g == 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;
int ans, a[1000001], n, maxi;
bool dk, check[1000001];
void sieve() {
  a[0] = a[1] = 1;
  for (int i = 2; i * i <= 1000000; i++) {
    if (a[i] != 0)
      continue;
    for (int j = i * i; j <= 1000000; j += i)
      if (a[j] == 0)
        a[j] = i;
  }
}
void fact(int x) {
  int t = x, pre = 0;
  while (t != 1) {
    if (a[t] == 0)
      a[t] = t;
    if (check[a[t]] && a[t] != pre) {
      dk = true;
      break;
    } else
      check[a[t]] = true;
    pre = a[t], t /= a[t];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  sieve();
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans = i == 0 ? x : __gcd(ans, x);
    if (!dk)
      fact(x);
  }
  if (dk) {
    if (ans == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  } else
    cout << "pairwise coprime";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int ans, n, a[1000001];
bool dk, check[1000001];
void sieve() {
  a[0] = a[1] = 1;
  for (int i = 2; i * i <= 1000000; i++) {
    if (a[i] != 0)
      continue;
    a[i] = i;
    for (int j = i * i; j <= 1000000; j += i)
      if (a[j] == 0)
        a[j] = i;
  }
}
void fact(int x) {
  int t = x, pre = 0;
  while (t != 1) {
    if (check[a[t]] && a[t] != pre) {
      dk = true;
      break;
    } else
      check[a[t]] = true;
    pre = a[t], t /= a[t];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  sieve();
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans = i == 0 ? x : __gcd(ans, x);
    if (!dk)
      fact(x);
  }
  if (dk) {
    if (ans == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  } else
    cout << "pairwise coprime";
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}

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

  bool flag2 = false;
  int res = d[0];
  for (int i = 1; i < n; i++) {
    res = gcd(res, d[i]);
    if (res == 1) {
      flag2 = true;
      break;
    }
  }

  bool flag1 = true;

  set<int> s;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 2; j <= sqrt(d[i]); j++) {
      if (d[i] % j == 0) {
        if (s.count(j)) {
          flag1 = false;
          break;
        } else
          s.insert(j);
        while (d[i] % j == 0)
          d[i] /= j;
      }
    }

    if (d[i] > 1) {
      if (s.count(d[i]))
        flag1 = false;
      else
        s.insert(d[i]);
    }
  }

  if (flag1)
    return cout << "pairwise coprime" << endl, 0;

  if (flag2)
    return cout << "setwise coprime" << endl, 0;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}

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

  int m = 1e6 + 2;
  vector<int> prime;
  vector<bool> used(m, false);
  for (int i = 2; i < m; i++)
    if (!used[i]) {
      prime.pb(i);
      for (int j = i * 2; j < m; j += i)
        used[j] = true;
    }

  bool flag2 = false;
  int res = d[0];
  for (int i = 1; i < n; i++) {
    res = gcd(res, d[i]);
    if (res == 1) {
      flag2 = true;
      break;
    }
  }

  bool flag1 = true;

  set<int> s;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < len(prime) && d[i] > 0; j++) {
      // cout << d[i] << ' ' << prime[j] << endl;
      while (d[i] > 0 && d[i] % prime[j] == 0) {
        if (s.count(prime[j])) {
          flag1 = false;
        } else
          s.insert(prime[j]);
        while (d[i] > 0 && d[i] % prime[j] == 0)
          d[i] /= prime[j];
      }
    }
  }

  if (flag1)
    return cout << "pairwise coprime" << endl, 0;

  if (flag2)
    return cout << "setwise coprime" << endl, 0;

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;
const int inf = -1;
const int sz = 1000010;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gap ' '
#define lb lower_bound
#define ub upper_bound
#define SIN(x) sin(x *pi / 180.0)
#define COS(x) cos(x *pi / 180.0)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) sort(x.begin(), x.end())
#define rall(x) reverse(x.begin(), x.end())
#define dbg puts("finding wrong")
#define case(x, y) printf("Case %lld: %lld\\n", ++x, y)
#define fastio                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)

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

int main() {
  fastio;
  int i, n, g = 0, c = 0;

  cin >> n;
  vector<int> ar(n);
  vector<int> cnt(sz);

  for (i = 0; i < n; i++) {
    cin >> ar[i];
    cnt[ar[i]]++;
    g = gcd(g, ar[i]);
  }

  for (i = 2; i <= sz; i++) {
    c = 0;
    for (int j = i; j <= sz; j += i) {
      c += cnt[j];
    }
    if (c > 1)
      break;
  }
  if (i == sz + 1) {
    printf("pairwise coprime\\n");
  } else if (g == 1) {
    printf("setwise coprime\\n");
  } else
    printf("not coprime\\n");

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;
const int inf = -1;
const int sz = 1e6;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gap ' '
#define lb lower_bound
#define ub upper_bound
#define SIN(x) sin(x *pi / 180.0)
#define COS(x) cos(x *pi / 180.0)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) sort(x.begin(), x.end())
#define rall(x) reverse(x.begin(), x.end())
#define dbg puts("finding wrong")
#define case(x, y) printf("Case %lld: %lld\\n", ++x, y)
#define fastio                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)

int ar[sz + 10];
int cnt[sz + 10];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  fastio;
  int i, n, g = 0, c = 0;

  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> ar[i];
    cnt[ar[i]]++;
    g = gcd(g, ar[i]);
  }

  for (i = 2; i <= 1000010; i++) {
    c = 0;
    for (int j = i; j <= 1000010; j += i) {
      c += cnt[j];
    }
    if (c > 1)
      break;
  }
  if (i == 1000011) {
    printf("pairwise coprime\\n");
  } else if (g == 1) {
    printf("setwise coprime\\n");
  } else
    printf("not coprime\\n");

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

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