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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

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

int n;
int a[1000000];
int vcnt[1000001];
bool isPrime[1000001];
int cnt[1000001]; // cnt[p] = 素因数pを持つa[i]の個数

bool checkPair() {
  int i, j;

  int MAX = 1000000;
  for (i = 2; i <= MAX; i++)
    isPrime[i] = true;
  for (i = 2; i <= MAX; i++) {
    if (isPrime[i]) {
      cnt[i] += vcnt[i];
      for (j = i * 2; j <= MAX; j += i) {
        isPrime[j] = false;
        cnt[i] += vcnt[j];
      }
    }
  }

  for (i = 2; i <= MAX; i++) {
    if (cnt[i] >= 2)
      break;
  }
  if (i > MAX) {
    return true;
  }
  return false;
}

signed main() {
  int i, j;

  scanf("%d", &n);
  rep(i, n) {
    scanf("%d", a + i);
    vcnt[a[i]]++;
  }

  if (checkPair()) {
    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;
    return 0;
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

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

int n;
int a[1000000];
map<int, int> mp;
bool isPrime[1000001];
int cnt[1000001]; // cnt[p] = 素因数pを持つa[i]の個数

signed main() {
  int i, j;

  scanf("%d", &n);
  rep(i, n) {
    scanf("%d", a + i);
    mp[a[i]]++;
  }

  int MAX = 1000000;
  for (i = 2; i <= MAX; i++)
    isPrime[i] = true;
  for (i = 2; i <= MAX; i++) {
    if (isPrime[i]) {
      cnt[i] += mp[i];
      for (j = i * 2; j <= MAX; j += i) {
        isPrime[j] = false;
        cnt[i] += mp[j];
      }
    }
  }

  for (i = 2; i <= MAX; i++) {
    if (cnt[i] >= 2)
      break;
  }
  if (i > MAX) {
    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;
    return 0;
  }

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

#include <bits/stdc++.h>

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

int N;
bool pairwise = true, setwise = true;
int main() {
  clock_t start = clock(); // スタート時間
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  map<long long, bool> factor;
  map<long long, long long> f_cnt;

  for (int k = 0; k < N; k++) {
    long long Num = A[k];
    for (long long i = 2LL; i * i <= Num; i++) {
      if (Num % i == 0LL && factor[i])
        pairwise = false;
      if (Num % i == 0LL)
        factor[i] = true, f_cnt[i]++;
      while (Num % i == 0LL)
        Num /= i;
    }
    if (Num != 1LL) {
      if (factor[Num])
        pairwise = false;
      factor[Num] = true, f_cnt[Num]++;
    }
    clock_t end = clock(); // 終了時間
    if ((double)(end - start) / CLOCKS_PER_SEC > 1.5) {
      cout << "setwise coprime" << endl;
      return 0;
    }
    // cout<<(double)(end - start) / CLOCKS_PER_SEC<<endl;
  }

  for (auto x : f_cnt)
    if (x.second == N)
      setwise = false;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

int N;
bool pairwise = true, setwise = true;
int main() {
  clock_t start = clock(); // スタート時間
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  map<long long, bool> factor;
  map<long long, long long> f_cnt;

  for (int k = 0; k < N; k++) {
    long long Num = A[k];
    for (long long i = 2LL; i * i <= Num; i++) {
      if (Num % i == 0LL && factor[i])
        pairwise = false;
      if (Num % i == 0LL)
        factor[i] = true, f_cnt[i]++;
      while (Num % i == 0LL)
        Num /= i;
    }
    if (Num != 1LL) {
      if (factor[Num])
        pairwise = false;
      factor[Num] = true, f_cnt[Num]++;
    }
    clock_t end = clock(); // 終了時間
    if ((double)(end - start) / CLOCKS_PER_SEC > 2.0) {
      cout << "not coprime" << endl;
      return 0;
    }
  }

  for (auto x : f_cnt)
    if (x.second == N)
      setwise = false;

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

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

vector<int> prime(int N) {
  vector<int> factor(N + 1); // factor[i]:iの最小の素因数 iが素数の場合は0
  factor[0] = 0, factor[1] = 0; // for osa_k
  for (int i = 2; i * i <= N; i++) {
    if (factor[i] != 0)
      continue;
    for (int j = i * 2; j <= N; j += i)
      if (factor[j] == 0)
        factor[j] = i;
  }
  return factor;
}
vector<int> S(1000001);

map<int, int> osa_k(int N) {
  // vector<int>factor=prime(N);
  map<int, int> prime_factor;
  for (; S[N] != 0; N /= S[N])
    prime_factor[S[N]]++;
  prime_factor[N]++;
  return prime_factor;
}

int N;
bool pairwise = true, setwise = true;
int main() {
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  map<long long, bool> factor;
  map<long long, long long> f_cnt;

  S = prime(1000001);

  for (int k = 0; k < N; k++) {
    long long Num = A[k];
    if (Num == 1)
      continue;
    auto p = osa_k(Num);
    for (auto x : p) {
      if (factor[x.first])
        pairwise = false;
      factor[x.first] = true;
      f_cnt[x.first]++;
    }
  }

  for (auto x : f_cnt)
    if (x.second == N)
      setwise = false;

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

Error: TLE

Fixed submission:

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

vector<long long> prime(long long N) {
  vector<long long> factor(N + 1); // factor[i]:iの最小の素因数 iが素数の場合は0
  factor[0] = -1, factor[1] = -1;
  for (int i = 2; i * i <= N; i++) {
    if (factor[i] != 0)
      continue;
    for (int j = i * 2; j <= N; j += i)
      if (factor[j] == 0)
        factor[j] = i;
  }
  return factor;
}
vector<long long> S(10000000);
map<long long, int> prime_factor(long long N) {
  // vector<int>factor=prime(N);
  map<long long, int> prime_factor;
  for (; S[N] != 0; N /= S[N])
    prime_factor[S[N]]++;
  prime_factor[N]++;
  return prime_factor;
}

int N;
bool pairwise = true, setwise = true;
int main() {
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  map<long long, bool> factor;
  map<long long, long long> f_cnt;

  S = prime(10000000);

  for (int k = 0; k < N; k++) {
    long long Num = A[k];
    // cout<<"Num:"<<Num<<endl;
    auto p = prime_factor(Num);
    for (auto x : p) {
      if (factor[x.first])
        pairwise = false;
      factor[x.first] = true;
      f_cnt[x.first]++;
    }
  }

  for (auto x : f_cnt)
    if (x.second == N)
      setwise = false;

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

#include <bits/stdc++.h>

const int MAX_N = 1000005;
int N;
int prime_arr[MAX_N];
int prime_cts2[MAX_N];
int prime_cts[MAX_N];
int vals[MAX_N];
std::vector<int> primes[MAX_N];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    vals[v]++;
  }

  for (int64_t i = 2; i < MAX_N; ++i) {
    if (prime_arr[i])
      continue;
    prime_arr[i] = true;
    primes[i].push_back(i);
    for (int64_t j = i * i; j < MAX_N; j += i) {
      if (prime_arr[j] == 0)
        primes[j].push_back(i);
      prime_arr[j] = true;
    }
  }
  bool pairwise = true;
  bool setwise = true;
  for (int i = 0; i < MAX_N; ++i) {
    // printf("I: %d\\n", i);
    for (int k = 0; k < vals[i]; ++k) {
      int v = i;
      // printf("v:%d\\n", v);
      while (v > 1) {
        int z = v;
        // printf("sz: %d %d\\n", primes[z].size(), z);
        for (int p : primes[z]) {
          // printf("%d ", p);
          if (prime_cts[p] && v % p == 0)
            pairwise = false;
          bool had_prime = false;
          while (v % p == 0) {
            v /= p;
            had_prime = true;
          }
          if (had_prime) {
            prime_cts[p] = 1;
            prime_cts2[p] += 1;
            if (prime_cts2[p] == N)
              setwise = false;
          }
        }
      }
      // printf("\\n");
    }
  }
  if (pairwise)
    printf("pairwise coprime\\n");
  else if (setwise)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

const int MAX_N = 1000005;
int N;
int vals[MAX_N];
int prime_arr[MAX_N];
int prime_cts2[MAX_N];
int prime_cts[MAX_N];
std::vector<int> primes;

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

int main() {
  for (int64_t i = 2; i < MAX_N; ++i) {
    if (prime_arr[i])
      continue;
    for (int64_t j = i * i; j < MAX_N; j += i)
      prime_arr[j] = true;
    primes.push_back(i);
  }
  scanf("%d", &N);
  bool pairwise = true;
  bool setwise = true;
  for (int i = 0; i < N; ++i) {
    scanf("%d", vals + i);
    int v = vals[i];
    int idx = 0;
    while (v > 1) {
      if (v % primes[idx] == 0 && prime_cts[primes[idx]])
        pairwise = false;
      bool had_prime = false;
      while (v % primes[idx] == 0) {
        had_prime = true;
        v /= primes[idx];
      }
      if (had_prime) {
        prime_cts[primes[idx]] = 1;
        prime_cts2[primes[idx]] += 1;
        if (prime_cts2[primes[idx]] == N)
          setwise = false;
      }
      idx++;
    }
  }
  if (pairwise)
    printf("pairwise coprime\\n");
  else if (setwise)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int maN = 1e6 + 5;
bool isPrime[maN];
int gcd(int a, int b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}
bool visited[maN];
int main() {
  int n;
  // sieve();
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  int pw = 1, sw = 1, ncp = 1;
  // int cnt = 0;

  for (int i = 0; i < n; ++i) {
    for (int j = 1; (ll)j * j <= a[i]; j++) {
      if (a[i] % j == 0 && j != 0) {
        if (visited[a[i] / j] && a[i] / j != 1) {
          pw = 0;
          break;
        }
        if (visited[j] && j != 1) {
          pw = 0;
          break;
        } else {
          visited[a[i] / j] = true;
          visited[j] = true;
        }
      }
    }
  }

  // for(int i = 0; i < n; ++i)
  // {
  //     if(!isPrime[a[i]])
  //         cnt++;
  // }
  // if(cnt < n-2)
  //     pw = 0;
  if (pw) {
    cout << "pairwise coprime";
    return 0;
  }
  int gcds = gcd(a[0], a[1]);

  for (int i = 2; i < n; ++i) {
    gcds = gcd(gcds, a[i]);
  }

  if (gcds != 1)
    sw = 0;

  if (sw)
    cout << "setwise coprime";
  else
    cout << "not coprime";

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
const int maN = 1e6 + 5;
int gcd(int a, int b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  int pw = 1, sw = 1, ncp = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {

      if (i != j) {
        if (gcd(a[i], a[j]) != 1) {
          pw = 0;
          break;
        }
      }
    }
    if (!pw)
      break;
  }
  int gcds = gcd(a[0], a[1]);

  for (int i = 2; i < n; ++i) {
    gcds = gcd(gcds, a[i]);
  }

  if (gcds != 1)
    sw = 0;

  if (pw)
    cout << "pairwise coprime";
  else if (sw)
    cout << "setwise coprime";
  else
    cout << "not coprime";

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

#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

vector<pair<int, int>> factor(int n) {
  vector<pair<int, int>> res;
  for (int i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    int ex = 0;
    while (n % i == 0) {
      ex++;
      n /= i;
    }
    res.push_back({i, ex});
  }
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int a;
    cin >> a;
    vector<pair<int, int>> f;
    f = factor(a);
    for (auto x : f) {
      mp[x.first]++;
    }
  }
  int k = 0;
  for (auto x : mp) {
    k = max(k, x.second);
  }
  if (k == n)
    cout << "not coprime" << endl;
  else if (k > 1)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define N 200000
#define WHITE 0
#define BLACK 1
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

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

vector<pair<ll, int>> factor(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    int ex = 0;
    while (n % i == 0) {
      ex++;
      n /= i;
    }
    res.push_back({i, ex});
  }
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int a;
    cin >> a;
    vector<pair<ll, int>> f;
    f = factor(a);
    for (auto x : f) {
      mp[x.first]++;
    }
  }
  int k = 0;
  for (auto x : mp) {
    k = max(k, x.second);
  }
  if (k == n)
    cout << "not coprime" << endl;
  else if (k > 1)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded


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

#define N 1000009
int su[N], cnt;
int n, arr[N];
bool isprime[N];
void prime() {
  cnt = 1;
  memset(isprime, 1, sizeof(isprime)); // 初始化认为所有数都为素数
  isprime[0] = isprime[1] = 0;         // 0和1不是素数
  for (int i = 2; i <= N; i++) {
    if (isprime[i])
      su[cnt++] = i; // 保存素数i
    for (int j = 1; j < cnt && su[j] * i < N; j++) {
      isprime[su[j] * i] = 0; // 筛掉小于等于i的素数和i的积构成的合数
    }
  }
}
map<int, int> mp;
signed main() {
  prime();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &arr[i]);
  int tmp = arr[1];
  for (int i = 1; i <= n; i++)
    tmp = __gcd(tmp, arr[i]);
  int F = 1; // 是否互质
  for (int i = 1; i <= n; i++) {
    if (isprime[arr[i]]) {
      if (mp[arr[i]]) {
        F = 0;
        break;
      }
      mp[arr[i]] = 1;
    } else {
      int temp = arr[i];
      for (int j = 1; j < cnt; j++) {
        if (temp % su[j] == 0) {
          if (mp[su[j]]) {
            F = 0;
            break;
          }
          mp[su[j]] = 1;
        }
        if (su[j] > temp)
          break;
      }
    }
    if (!F)
      break;
  }
  if (F)
    cout << "pairwise coprime";
  else if (tmp == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}


Error: TLE

Fixed submission:


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

#define N 1000009
int su[N], cnt;
int n, arr[N];
bool isprime[N];
void prime() {
  cnt = 1;
  memset(isprime, 1, sizeof(isprime)); // 初始化认为所有数都为素数
  isprime[0] = isprime[1] = 0;         // 0和1不是素数
  for (int i = 2; i <= N; i++) {
    if (isprime[i])
      su[cnt++] = i; // 保存素数i
    for (int j = 1; j < cnt && su[j] * i < N; j++) {
      isprime[su[j] * i] = 0; // 筛掉小于等于i的素数和i的积构成的合数
    }
  }
}
map<int, int> mp;
signed main() {
  prime();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &arr[i]);
  int tmp = arr[1];
  for (int i = 1; i <= n; i++)
    tmp = __gcd(tmp, arr[i]);
  int F = 1; // 是否互质
  for (int i = 1; i <= n; i++) {
    if (isprime[arr[i]]) {
      if (mp[arr[i]]) {
        F = 0;
        break;
      }
      mp[arr[i]] = 1;
    } else {
      int temp = arr[i];
      for (int j = 1; j < cnt; j++) {
        if (temp % su[j] == 0) {
          if (mp[su[j]]) {
            F = 0;
            break;
          }
          mp[su[j]] = 1;
          while (temp % su[j] == 0)
            temp /= su[j];
        }
      }
    }
    if (!F)
      break;
  }
  if (F)
    cout << "pairwise coprime";
  else if (tmp == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// FILE *fi = freopen("1.txt", "r", stdin);
// FILE *fo = freopen("1", "w", stdout);
// FILE *fi = freopen("P.inp", "r", stdin);
// FILE *fo = freopen("P.out", "w", stdout);
bool used[1000001];
void bfs(int x) {
  queue<int> q;
  if (used[x])
    return;
  q.push(x);
  used[x] = true;
  while (q.size()) {
    int u = q.front();
    q.pop();
    used[u] = true;
    u += x;
    if (u <= 1e6 && !used[u])
      q.push(u);
  }
  return;
}
int a[1000001];
int Min[1000001];
int main() {
  //------------------------------
  // Faster
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //------------------------------
  int N = 1e6;
  for (int i = 1; i <= N; i++)
    Min[i] = i;
  for (int i = 2; i <= sqrt(N); i++) {
    for (int j = i; j <= N; j += i) {
      Min[j] = min(Min[j], i);
    }
  }
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  bool ok = false;
  int G = 0;
  for (int i = n; i >= 1; i--) {
    G = __gcd(G, a[i]);
    if (a[i] == 1)
      continue;
    vector<int> U;
    while (a[i] > 1) {
      int x = Min[a[i]];
      if (used[x]) {
        ok = true;
      }
      U.push_back(x);
      a[i] /= x;
    }
    for (auto x : U)
      bfs(x);
  }
  if (ok == false) {
    cout << "pairwise coprime";
  } else if (ok == true && G == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// FILE *fi = freopen("1.txt", "r", stdin);
// FILE *fo = freopen("1", "w", stdout);
// FILE *fi = freopen("P.inp", "r", stdin);
// FILE *fo = freopen("P.out", "w", stdout);
bool used[1000001];
void bfs(int x) {
  queue<int> q;
  if (used[x])
    return;
  q.push(x);
  used[x] = true;
  while (q.size()) {
    int u = q.front();
    q.pop();
    used[u] = true;
    u += x;
    if (!used[u] && u <= 1e6)
      q.push(u);
  }
  return;
}
int a[1000001];
int Min[1000001];
int main() {
  //------------------------------
  // Faster
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //------------------------------
  int N = 1e6;
  for (int i = 1; i <= N; i++)
    Min[i] = i;
  for (int i = 2; i <= sqrt(N); i++) {
    for (int j = i; j <= N; j += i) {
      Min[j] = min(Min[j], i);
    }
  }
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  bool ok = false;
  int G = 0;
  for (int i = n; i >= 1; i--) {
    G = __gcd(G, a[i]);
    if (a[i] == 1)
      continue;
    vector<int> U;
    while (a[i] > 1) {
      int x = Min[a[i]];
      if (used[x]) {
        ok = true;
      }
      U.push_back(x);
      a[i] /= x;
    }
    for (auto x : U)
      bfs(x);
  }
  if (ok == false) {
    cout << "pairwise coprime";
  } else if (ok == true && G == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 1000007
#define MO (int(1e9) + 7)
int a[MAXN];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int v[MAXN];
bool vis[MAXN];
inline void db() {
  memset(v, 0, sizeof v);
  for (int i = 2; i <= 1000000; i++)
    if (!v[i]) {
      v[i] = i;
      for (long long j = 1ll * i * i; j <= 1000000; j += i) {
        v[j] = i;
      }
    }
}
int n;
inline bool vali() {
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < n; i++) {
    int x = a[i];
    while (x > 1) {
      if (vis[v[x]]) {
        return false;
      }
      vis[v[x]] = true;
      int ss = v[x];
      do {
        x /= ss;
      } while (x % ss == 0);
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  db();
  cin >> n;
  int g = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    g = gcd(g, a[i]);
  }
  if (g == 1) {
    if (vali()) {
      cout << "pairwise coprime\\n";
    } else {
      cout << "setwise coprime\\n";
    }
  } else {
    cout << "not coprime\\n";
  }
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 1000007
#define MO (int(1e9) + 7)
int a[MAXN];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int v[MAXN];
bool vis[MAXN];
inline void db() {
  memset(v, 0, sizeof v);
  for (int i = 2; i <= 1000; i++)
    if (!v[i]) {
      v[i] = i;
      for (int j = i * i; j <= 1000000; j += i) {
        v[j] = i;
      }
    }
}
int n;
inline bool vali() {
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < n; i++) {
    int x = a[i];
    while (x > 1) {
      if (vis[v[x]]) {
        return false;
      }
      vis[v[x]] = true;
      int ss = v[x];
      do {
        x /= ss;
      } while (x % ss == 0);
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  db();
  cin >> n;
  int g = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    g = gcd(g, a[i]);
  }
  if (g == 1) {
    if (vali()) {
      cout << "pairwise coprime\\n";
    } else {
      cout << "setwise coprime\\n";
    }
  } else {
    cout << "not coprime\\n";
  }
}