alexjercan/bugnet huggingface dataset:
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

vector<int> Eratosthenes(const int N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  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;
}

ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  // xの方が常に大きい
  ll r;
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll ma = -1;
  map<int, int> mp;
  rep(i, N) {
    cin >> A[i];
    mp[A[i]]++;
    ma = max(ma, A[i]);
  }
  ll SA = A[0];
  rep(i, N - 1) { SA = gcd(SA, A[i + 1]); }

  bool is_P = true, is_S = false;
  if (SA == 1)
    is_S = true;

  if (ma == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  vector<int> prime = Eratosthenes(ma);

  for (int i = 0; i <= prime.size(); i++) {
    int p = prime[i];
    int x = p;
    if (p == 0)
      continue;
    int tmp = 0, cnt = 1;
    while (x <= ma) {
      // cout << x << " " << tmp << endl;
      cnt++;
      tmp += mp[x];
      x = p * cnt;
    }
    if (tmp >= 2) {
      is_P = false;
      break;
    }
  }

  if (is_P)
    cout << "pairwise coprime" << endl;
  else if (is_S)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

Error: 0

Fixed submission:

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

vector<int> Eratosthenes(const int N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  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;
}

ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  // xの方が常に大きい
  ll r;
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll ma = -1;
  map<int, int> mp;
  rep(i, N) {
    cin >> A[i];
    mp[A[i]]++;
    ma = max(ma, A[i]);
  }
  ll SA = A[0];
  rep(i, N - 1) { SA = gcd(SA, A[i + 1]); }

  bool is_P = true, is_S = false;
  if (SA == 1)
    is_S = true;

  vector<int> prime = Eratosthenes(ma);

  for (int i = 0; i <= prime.size(); i++) {
    int p = prime[i];
    int x = p;
    if (p == 0)
      continue;
    int tmp = 0, cnt = 1;
    while (x <= ma) {
      // cout << x << " " << tmp << endl;
      cnt++;
      tmp += mp[x];
      x = p * cnt;
    }
    if (tmp >= 2) {
      is_P = false;
      break;
    }
  }

  if (is_P)
    cout << "pairwise coprime" << endl;
  else if (is_S)
    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 max_n = 1e6 + 6;
vector<int> spf;

void sieve() {
  spf.resize(max_n, 1);

  for (int num = 2; num < max_n; num++)
    spf[num] = num;

  for (int num = 2; num < max_n; num++) {
    if (spf[num] != num)
      continue;

    for (int mult = 2 * num; mult < max_n; mult += num)
      spf[mult] = num;
  }
}

void solve() {
  int n;
  cin >> n;

  vector<int> a(n);
  for (auto &ele : a)
    cin >> ele;

  vector<bool> present(max_n, false);
  bool first = true;

  for (int i = 0; i < n; i++) {
    int num = a[i];
    while (num != 1) {
      int pf = spf[num];
      if (present[pf] == true)
        first = false;

      present[pf] = true;
      while (num % pf == 0)
        num /= pf;
    }
  }

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

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

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

  sieve();
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define SPEED                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define ld long double
const ll mod = 1000000007;
int main() {
  SPEED
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int g = arr[0];
  for (int i = 1; i < n; ++i) {
    g = __gcd(g, arr[i]);
  }
  if (g > 1) {
    cout << "not coprime";
    return 0;
  }

  vector<int> nos;
  bool signal = false;
  for (int i = 0; i < n; ++i) {
    if (nos.size() == 0) {
      nos.push_back(arr[i]);
      continue;
    }

    for (int j = 0; j < nos.size(); ++j) {
      if (__gcd(arr[i], nos[j]) > 1) {
        signal = true;
        break;
      }
    }
    if (signal) {
      break;
    }

    nos.push_back(arr[i]);
  }

  if (signal) {
    cout << "setwise coprime";
  } else {
    cout << "pairwise coprime";
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int g = 0, a = 0, b = 0;
  vector<int> d(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    g = __gcd(g, d[i]);
    if (d[i] % 2) {
      a++;
    } else {
      b++;
    }
  }
  if (g != 1) {
    cout << "not coprime";
  } else {
    if (b >= 2) {
      cout << "setwise coprime";
    } else {
      map<int, int> k;
      for (int i = 0; i < n; i++) {
        if (d[i] == 1) {
          continue;
        }
        int j = 2;
        for (j = 2; j * j < d[i]; j++) {
          if (d[i] % j == 0) {
            k[j]++;
            if (k[j] >= 2) {
              cout << "setwise coprime";
              return 0;
            }
            k[d[i] / j]++;
            if (k[d[i] / j] >= 2) {
              cout << "setwise coprime";
              return 0;
            }
          }
        }
        if (j * j == d[i]) {
          k[j]++;
          if (k[j] >= 2) {
            cout << "setwise coprime";
            return 0;
          }
        }
        k[d[i]]++;
        if (k[d[i]] >= 2) {
          cout << "setwise coprime";
          return 0;
        }
      }
      cout << "pairwise coprime";
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int g = 0, a = 0, b = 0;
  vector<int> d(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    g = __gcd(g, d[i]);
    if (d[i] % 2) {
      a++;
    } else {
      b++;
    }
  }
  if (g != 1) {
    cout << "not coprime";
  } else {
    if (b >= 2) {
      cout << "setwise coprime";
    } else {
      for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          if (__gcd(d[i], d[j]) != 1) {
            cout << "setwise coprime";
            return 0;
          }
        }
      }
      cout << "pairwise coprime";
    }
  }

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

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

const int N = 1e6 + 5;
int arr[N];

int spf[N];
map<int, int> fact;
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < N; i++)

    // marking smallest prime factor for every
    // number to be itself.
    spf[i] = i;

  // separately marking spf for every even
  // number as 2
  for (int i = 4; i < N; i += 2)
    spf[i] = 2;

  for (int i = 3; i * i < N; i++) {
    // checking if i is prime
    if (spf[i] == i) {
      // marking SPF for all numbers divisible by i
      for (int j = i * i; j < N; j += i)

        // marking spf[j] if it is not
        // previously marked
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}
void getFactorization(int x) {
  set<int> ret;
  while (x != 1) {
    ret.insert(spf[x]);
    x = x / spf[x];
  }
  for (auto i : ret) {
    fact[i]++;
  }
}

int32_t main() {

  fast int n;
  cin >> n;
  sieve();
  cin >> arr[0];
  int gcd = arr[0];
  getFactorization(arr[0]);
  for (int i = 1; i < n; i++) {
    cin >> arr[i];
    getFactorization(arr[i]);
    gcd = __gcd(arr[i], gcd);
  }
  bool flag = true;
  for (auto i : fact) {
    if (i.second >= 2) {
      flag = false;
      break;
    }
  }
  if (gcd == 1 && flag) {
    cout << "pairwise coprime";
  } else if (gcd == 1 && !flag) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

const int N = 1e6 + 5;
int arr[N];
map<int, int> factors;
bool f;
void trial_division1(long long n) {
  for (long long d = 2; d * d <= n; d++) {
    f = false;
    while (n % d == 0) {
      n /= d;
      f = true;
    }
    if (f)
      factors[d]++;
  }
  if (n > 1)
    factors[n]++;
}
int32_t main() {

  fast int n;
  cin >> n;
  cin >> arr[0];
  int gcd = arr[0];
  trial_division1(arr[0]);
  for (int i = 1; i < n; i++) {
    cin >> arr[i];
    gcd = __gcd(arr[i], gcd);
    trial_division1(arr[i]);
  }
  bool flag = true;
  for (auto i : factors) {
    if (i.second >= 2) {
      // cout << i.second << " ** ";
      flag = false;
      break;
    }
  }
  if (gcd == 1 && flag) {
    cout << "pairwise coprime";
  } else if (gcd == 1 && !flag) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }

  return 0;
}
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;
using ll = long long;
using P = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> cnt(1000005);
  vector<int> m(1000005);
  rep(i, n) m[a[i]]++;
  bool flag = true;
  for (int i = 2; i <= 1000000; i++) {
    int t = 0;
    if (cnt[i] != 0)
      continue;
    for (int j = i; j <= 1000000; j += i) {
      t += m[j];
      cnt[j]++;
    }
    if (t >= 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[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>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) scanf("%d", &a[i]);
  vector<int> cnt(1000005);
  rep(i, n) {
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        cnt[j]++;
        if (a[i] / j != j)
          cnt[a[i] / j]++;
      }
    }
  }
  bool flag = true;
  for (int i = 2; i <= 1000000; i++)
    if (cnt[i] > 1)
      flag = false;
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[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;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
template <typename T> vector<T> smallest_prime_factors(T n) {

  vector<T> spf(n + 1);
  for (int i = 0; i <= n; i++)
    spf[i] = i;

  for (T i = 2; i * i <= n; i++) {

    // 素数だったら
    if (spf[i] == i) {

      for (T j = i * i; j <= n; j += i) {

        // iを持つ整数かつまだ素数が決まっていないなら
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }

  return spf;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int G = A.at(0);
  for (int i = 1; i < N; i++) {
    G = gcd(G, A.at(i));
  }
  auto spf = smallest_prime_factors(1000000);
  unordered_map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int R = A.at(i);
    unordered_map<int, int> C;
    while (R > 1) {
      // cout<<R<<" "<<spf[R]<<endl;
      if (C[spf[R]] == 0)
        mp[spf[R]]++;
      C[spf[R]]++;
      R /= spf[R];
    }
  }
  int check = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (mp[i] >= 2) {
      check++;
    }
  }
  if (check == 0) {
    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;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
#define int long long
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int G = A.at(0);
  for (int i = 1; i < N; i++) {
    G = gcd(G, A.at(i));
  }
  unordered_map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int R = A.at(i);
    for (int j = 2; j * j <= R; j++) {
      if (R % j == 0) {
        mp[j]++;
      }
      while (R % j == 0 && R > 1) {
        R /= j;
      }
      if (R == 1) {
        break;
      }
      if (R == 1) {
        break;
      }
    }
    if (R != 1) {
      mp[R]++;
    }
  }
  int check = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (mp[i] >= 2) {
      check++;
    }
  }
  if (check == 0) {
    cout << "pairwise coprime" << endl;
  } else 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>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  int lim = 10e6;
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    int num;
    cin >> num;
    a[i] = num;
  }

  Sieve sieve(lim + 1);
  vector<int> memo(lim + 1);

  auto is_p = [&]() {
    for (int i = 0; i < n; i++) {
      auto list = sieve.factor(a[i]);
      for (auto p : list) {
        int num = p.first;
        // cout << num << endl;
        if (memo[num] > 0)
          return false;
        memo[num]++;
      }
    }
    return true;
  };

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

  auto is_s = [&]() {
    int g = a[0];
    for (int i = 1; i < n; i++) {
      g = gcd(g, a[i]);
      if (g == 1) {
        return true;
      }
    }
    return false;
  };

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

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


Error: TLE

Fixed submission:

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

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

int main() {
  int lim = 10e6;
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    int num;
    cin >> num;
    a[i] = num;
  }

  vector<bool> memo(lim + 1);

  auto is_p = [&]() {
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        if (gcd(a[i], a[j]) > 1) {
          return false;
        }
      }
    }
    return true;
  };

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

  auto is_s = [&]() {
    int g = a[0];
    for (int i = 1; i < n; i++) {
      g = gcd(g, a[i]);
      if (g == 1) {
        return true;
      }
    }
    return false;
  };

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

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

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout << "here\\n"
#define MOD 1000000009

const int MAXN = 1e6 + 15;

using namespace std;

int spf[MAXN];
int A[MAXN];
bool vis[MAXN];

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> A[i];
  int g = __gcd(A[0], A[1]);
  for (int i = 2; i < n; i++) {
    g = __gcd(g, A[i]);
  }
  if (g != 1) {
    cout << "not coprime";
    return;
  }
  for (int i = 2; i <= 1000000; i++) {
    spf[i] = i;
  }
  for (int i = 2; (ll)i * i <= 1000000; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= 1000000; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }

  spf[1] = 1;

  for (int i = 0; i < n; i++) {
    int x = A[i];
    while (x != 1) {
      int y = spf[x];
      if (vis[y]) {
        cout << "setwise coprime";
        return;
      }
      while (x % y == 0)
        x /= y;
      vis[y] = 1;
    }
  }
  cout << "pairwise coprime";
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);

  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\\n";
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout << "here\\n"
#define MOD 1000000009

const int MAXN = 2e5 + 15;

using namespace std;

int hp[1000001];
int A[1000001];
bool vis[1000001];

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> A[i];
  int g = __gcd(A[0], A[1]);
  for (int i = 2; i < n; i++) {
    g = __gcd(g, A[i]);
  }
  if (g != 1) {
    cout << "not coprime";
    return;
  }
  for (int i = 2; (ll)i * i <= 1000000; i++) {
    hp[i] = i;
  }
  for (int i = 2; (ll)i * i <= 1000000; i++) {
    if (hp[i] == i) {
      for (int j = i * i; j <= 1000000; j += i) {
        if (hp[j] == j)
          hp[j] = i;
      }
    }
  }

  hp[1] = 1;

  for (int i = 0; i < n; i++) {
    int x = A[i];
    while (x != 1) {
      int y = hp[x];
      if (vis[y] != 0) {
        cout << "setwise coprime";
        return;
      }
      while (x % y == 0)
        x /= y;
      vis[y] = 1;
    }
  }
  cout << "pairwise coprime";
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);

  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\\n";
  }

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

#pragma warning(disable : 4996)
#include <algorithm>
#include <stdio.h>
using namespace std;
int d[1001000];
int vis[1001000];
int gcd(int a, int b) {
  if (!a || !b)
    return a + b;
  else
    return a > b ? gcd(a % b, b) : gcd(a, b % a);
}
int a[1001000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  d[1] = 1;
  for (int i = 2; i <= 1000000; i++) {
    if (d[i] != 0)
      continue;
    for (int j = 1; j * i <= 1000000; j++)
      d[i * j] = i;
  }
  bool pairchk = 0;
  for (int i = 1; i <= n; i++) {
    int c = a[i];
    while (d[c] != c) {
      int p = d[c];
      if (vis[p]) {
        pairchk = 1;
        break;
      }
      vis[p] += 1;
      while (c % p == 0)
        c /= p;
    }
    if (pairchk)
      break;
    if (c == 1)
      continue;
    if (vis[c]) {
      pairchk = 1;
    }
    vis[c] += 1;
  }
  if (!pairchk) {
    printf("pairwise coprime");
    return 0;
  }
  int gcd_ = a[1];
  for (int i = 1; i <= n; i++) {
    gcd_ = gcd(a[i], gcd_);
  }
  if (gcd_ == 1) {
    printf("setwise coprime");
    return 0;
  }
  printf("not coprime");
}

Error: WA

Fixed submission:

#pragma warning(disable : 4996)
#include <algorithm>
#include <stdio.h>
using namespace std;
int d[1001000];
int vis[1001000];
int gcd(int a, int b) {
  if (!a || !b)
    return a + b;
  else
    return a > b ? gcd(a % b, b) : gcd(a, b % a);
}
int a[1001000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  d[1] = 1;
  for (int i = 2; i <= 16; i++) {
    if (d[i] != 0)
      continue;
    for (int j = 1; j * i <= 16; j++)
      d[i * j] = i;
  }
  bool pairchk = 0;
  for (int i = 1; i <= n; i++) {
    int c = a[i];
    while (d[c] != c) {
      int p = d[c];
      if (vis[p]) {
        pairchk = 1;
        break;
      }
      vis[p] += 1;
      while (c % p == 0)
        c /= p;
    }
    if (pairchk)
      break;
    if (c == 1)
      continue;
    if (vis[c]) {
      pairchk = 1;
    }
    vis[c] += 1;
  }
  if (!pairchk) {
    printf("pairwise coprime");
    return 0;
  }
  int gcd_ = a[1];
  for (int i = 1; i <= n; i++) {
    gcd_ = gcd(a[i], gcd_);
  }
  if (gcd_ == 1) {
    printf("setwise coprime");
    return 0;
  }
  printf("not coprime");
}