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> P;

const int INF = 1e9;
const int MOD = 1e9 + 7;

vector<ll> prime_table(ll n) { // 素数全列挙
  vector<ll> prime(n + 1);
  for (int i = 0; i <= n; i++) {
    prime[i] = i;
  }
  for (int i = 2; i * i <= n; i++) {
    if (prime[i] != i)
      continue;
    for (int j = 2 * i; j <= n; j += i) {
      if (prime[j] / i == 1)
        continue;
      prime[j] /= i;
    }
  }
  return prime; // i番目の要素が素数の場合trueを返す
}

int main() {
  int N;
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N);
  vector<ll> prime = prime_table(a[N - 1]);
  ll used[a[N - 1] + 1] = {};
  bool flag = true;
  for (int i = 0; i < N; i++) {
    set<ll> s;
    ll tmp = a[i];
    while (tmp > 1) {
      s.insert(prime[tmp]);
      tmp /= prime[tmp];
    }
    for (auto res : s) {
      if (used[res]) {
        // cout << res << endl;
        flag = false;
      }
      used[res] = true;
    }
  }
  ll ans = a[0];
  for (int i = 1; i < N; i++) {
    ans = __gcd(ans, a[i]);
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
  } else if (ans == 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;
typedef pair<int, int> P;

const int INF = 1e9;
const int MOD = 1e9 + 7;

const int max = 1000000;
int ans[1000001] = {};

vector<bool> prime_table(int n) { // 素数全列挙
  vector<bool> prime(n + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (prime[i] != true)
      continue;
    for (int j = 2 * i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime; // i番目の要素が素数の場合trueを返す
}

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<bool> prime = prime_table(1000000);
  vector<int> res;
  for (int i = 0; i <= 1000000; i++) {
    if (prime[i])
      res.push_back(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < res.size(); j++) {
      if (a[i] % res[j] == 0) {
        ans[res[j]]++;
      }
    }
  }
  bool flag = true;
  for (int i = 0; i <= 1000000; i++) {
    if (ans[i] > 1) {
      flag = false;
    }
  }
  int ans2 = a[0];
  for (int i = 1; i < N; i++) {
    ans2 = __gcd(a[i], ans2);
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
  } else if (ans2 == 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;

int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  bool isPairwise = true;
  for (int i = 2; i < 1000001; i++) {
    int same_divisor = 0;
    for (int j = i; j < 1000001; j += i) {
      same_divisor += cnt[j];
    }
    if (same_divisor > 1) {
      isPairwise = false;
      break;
    }
  }
  if (isPairwise) {
    cout << "pairwise coprime\\n";
    return 0;
  }

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

  return 0;
}


Error: WA

Fixed submission:

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

int factorCount[100001];
bool primeSet[1001];
void make_prime() {
  primeSet[1] = false;
  for (int i = 2; i < 1001; i++) {
    primeSet[i] = true;
  }
  for (int i = 2; i < 1001; i++) {
    if (primeSet[i]) {
      for (int j = i + i; j < 1001; j += i) {
        primeSet[j] = false;
      }
    }
  }
}
void factorize(int in) {
  int x = in;
  for (int i = 2; i <= in && x != 1; i++) {
    if (primeSet[i] && !(x % i)) {
      while (!(x % i)) {
        x /= i;
      }
      factorCount[i]++;
    }
  }
  if (x != 1) {
    factorCount[x]++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  make_prime();
  int max = -1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    factorize(x);
    if (max < x)
      max = x;
  }

  bool isPairwise = true, isSetwise = true;
  for (int i = 2; i <= max; i++) {
    cout << factorCount[i] << ' ';
    if (factorCount[i] > 1) {
      isPairwise = false;
    }
    if (factorCount[i] == n) {
      isSetwise = false;
    }
  }
  if (isPairwise) {
    cout << "pairwise coprime\\n";
    return 0;
  } else if (isSetwise) {
    cout << "setwise coprime\\n";
    return 0;
  }
  cout << "not coprime\\n";

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

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

const int N = 1000010;

ll gcd(ll m, ll n) { // 最大公約数
  if (n == 0)
    return m;
  return gcd(n, m % n);
} // gcd

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(N, 0);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }
  bool pairwise = 1;
  for (int i = 2; i <= N; i++) {
    int cnt = 0;
    for (int j = i; j <= N; j += i) {
      cnt += c[j];
    }
    if (cnt > 1)
      pairwise = 0;
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int p = 0;
  rep(i, n) { p = gcd(p, a[i]); }
  if (p == 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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll, ll>

ll gcd(ll m, ll n) { // 最大公約数
  if (n == 0)
    return m;
  return gcd(n, m % n);
} // gcd

const int N = 1000010;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<bool> isPrime(N + 1, 1);
  vector<int> Prime;
  for (int i = 2; i <= N; i++) {
    if (isPrime[i]) {
      Prime.push_back(i);
      for (int j = 2 * i; j <= N; j += i)
        isPrime[j] = 0;
    }
  }
  bool ans1 = 1, ans2 = 1;
  map<int, int> mp;
  rep(i, n) {
    for (auto x : Prime) {
      if (a[i] % x == 0) {
        if (mp[x] != 0)
          ans1 = 0;
        mp[x] = 1;
      }
    }
  }
  int p = 0;
  rep(i, n) { p = gcd(p, a[i]); }
  if (p != 1)
    ans2 = 0;
  if (ans1)
    cout << "pairwise coprime" << endl;
  else if (ans2)
    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++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int A = 1e6 + 9;
const int MAX = A;
vector<int> is_prime(MAX, 1);
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int main() {
  is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i) {
    if (!is_prime[i])
      continue;
    for (int j = i * 2; j < MAX; j += i)
      is_prime[j] = 0;
  }
  //---------------
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(A);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }
  bool pairwize = true;
  rep2(i, 2, A) {
    if (!is_prime[i])
      continue;
    int cnt = 0;
    for (int j = 1; i * j <= A; ++j) {
      cnt += c[i * j];
      if (cnt > 1)
        pairwize = false;
    }
  }
  if (pairwize) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = 0;
  rep(i, n) {
    g = (int)GCD((ll)g, (ll)a[i]);
    if (g == 1) {
      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++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(ALL(A));
  int g = 0;
  rep(i, N - 1) rep2(j, i + 1, N) {
    g = GCD(g, A[i]);
    int p = GCD(A[i], A[j]);
    if (p != 1) {
      g = GCD(p, g);
      vector<int> Q;
      rep2(x, i + 1, N - 1) {
        Q.pb(GCD(A[i], A[j]));
        if (Q[x] == 1) {
          cout << "setwise coprime" << endl;
          return 0;
        }
      }
      rep2(k, i + 1, N) {
        g = GCD(g, A[k]);
        if (g == 1) {
          cout << "setwise coprime" << endl;
          return 0;
        }
      }
      if (g == 1) {
        cout << "setwise coprime" << endl;
        return 0;
      } else {
        cout << "not coprime" << endl;
        return 0;
      }
    }
  }
  cout << "pairwise coprime" << endl;

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

#include <algorithm>
#include <chrono>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp                                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

set<int> smth;
ll lp[SIZE + 2], pr[SIZE + 2];

int gcd(int a, int b) {
  while (a * b != 0) {
    a %= b;
    swap(a, b);
  }
  return a + b;
}

bool flag = 0;

void fact(int a) {
  int d = 2;
  set<int> dd;
  if (a < 2)
    return;
  while (a > 1) {
    dd.insert(lp[a]);
    a /= lp[a];
  }

  for (auto cur : dd) {
    if (smth.find(cur) != smth.end())
      flag = 1;
  }

  for (int i : dd)
    smth.insert(i);
}

int main() {
  fastInp;

  ll n;
  cin >> n;
  vector<ll> vec(n);

  for (ll i = 2; i < SIZE; i++) {
    if (pr[i])
      continue;

    lp[i] = i;
    for (ll j = (i * i); j < SIZE; j += i) {
      pr[j] = 1;
      lp[j] = i;
    }
  }

  for (auto &i : vec)
    cin >> i;

  int ans = vec[0];
  for (int i = 0; i < n; i++) {
    ans = gcd(ans, vec[i]);
    fact(vec[i]);
  }

  if (flag == 0)
    cout << "pairwise coprime\\n";
  else if (ans == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <chrono>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp                                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

set<int> smth;
ll lp[SIZE + 2], pr[SIZE + 2];

int gcd(int a, int b) {
  while (a * b != 0) {
    a %= b;
    swap(a, b);
  }
  return a + b;
}

bool flag = 0;

void fact(int a) {
  int d = 2;
  set<int> dd;
  if (a < 2)
    return;
  while (a > 1) {
    dd.insert(lp[a]);
    a /= lp[a];
  }

  for (int i : dd)
    smth.insert(i);
}

int main() {
  fastInp;

  ll n;
  cin >> n;
  vector<ll> vec(n);

  for (int i = 2; i < SIZE; i++) {
    if (pr[i])
      continue;

    lp[i] = i;
    for (ll j = (i * i); j < SIZE; j += i) {
      pr[j] = 1;
      lp[j] = i;
    }
  }
  for (auto &i : vec)
    cin >> i;

  int ans = vec[0];
  for (int i = 0; i < n; i++) {
    ans = gcd(ans, vec[i]);
    fact(vec[i]);
  }

  if (flag == 0)
    cout << "pairwise coprime\\n";
  else if (ans == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";

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

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

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

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll n, i, j;

  cin >> n;
  ll a[n];

  ll prime[1000003];

  memset(prime, 0, sizeof(prime));

  for (i = 2; i < 1000001; i++) {
    if (prime[i] == 0) {
      for (j = i; j < 1000001; j += i) {
        prime[j] = i;
      }
    }
  }

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

  map<ll, ll> pf;

  for (i = 0; i < n; i++) {
    map<ll, ll> m;

    ll x = a[i];

    while (x != 1) {
      if (m.find(prime[x]) == m.end()) {
        m.insert(mp(prime[x], 1));
      }

      x /= prime[x];
    }

    for (auto it : m) {
      if (pf.find(it.first) != pf.end())
        pf.find(it.first)->second++;
      else
        pf.insert(mp(it.first, 1));
    }
  }

  ll flag1 = 0, flag2 = 0;
  for (auto it : pf) {
    if (it.second != 1)
      flag1 = 1;
    if (it.second == n)
      flag2 = 1;
  }

  if (flag1 == 0)
    cout << "pairwise coprime\\n";
  else if (flag2 == 0)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}

Error: -11

Fixed submission:

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

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

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll n, i, j;

  cin >> n;
  ll a[i];

  ll prime[1000003];

  memset(prime, 0, sizeof(prime));

  for (i = 2; i < 1000001; i++) {
    if (prime[i] == 0) {
      for (j = i; j < 1000001; j += i) {
        prime[j] = i;
      }
    }
  }

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

  map<ll, ll> pf;

  for (i = 0; i < n; i++) {
    map<ll, ll> m;

    ll x = a[i];

    while (x != 1) {
      if (m.find(prime[x]) == m.end()) {
        m.insert(mp(prime[x], 1));
      }

      x /= prime[x];
    }

    for (auto it : m) {
      if (pf.find(it.first) != pf.end())
        pf.find(it.first)->second++;
      else
        pf.insert(mp(it.first, 1));
    }
  }

  ll flag1 = 0, flag2 = 0;
  for (auto it : pf) {
    if (it.second != 1)
      flag1 = 1;
    if (it.second == n)
      flag2 = 1;
  }

  if (flag1 == 0)
    cout << "pairwise coprime\\n";
  else if (flag2 == 0)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define pb push_back

using namespace std;

#define MAXN 1000001

int spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++)
    spf[i] = i;
  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;

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

unordered_set<int> st[1000001];

void fact(int x, int i) {
  while (x != 1) {
    st[spf[x]].insert(i);
    x = x / spf[x];
  }
}

void test() {
  int n;
  cin >> n;
  int a[n];
  f(i, n) cin >> a[i];
  f(i, n) { fact(a[i], i); }
  bool ty1 = true, ty2 = true, ty3 = true;
  f(i, 1000001) {
    if (st[i].size() > 1)
      ty1 = false;
    if ((int)st[i].size() == n)
      ty2 = false;
  }
  if (ty1)
    cout << "pairwise coprime\\n";
  else if (ty2)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  sieve();
  int tests = 1;
  // cin>>tests;
  while (tests--) {
    test();
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define pb push_back

using namespace std;

#define MAXN 1000001

int spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++)
    spf[i] = i;
  for (int i = 4; i < MAXN; i += 2)
    spf[i] = 2;

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

set<int> st[1000001];

void fact(int x, int i) {
  while (x != 1) {
    st[spf[x]].insert(i);
    x = x / spf[x];
  }
}

void test() {
  int n;
  cin >> n;
  int a[n];
  f(i, n) cin >> a[i];
  f(i, n) { fact(a[i], i); }
  bool ty1 = true, ty2 = true, ty3 = true;
  f(i, 1000001) {
    if (st[i].size() > 1)
      ty1 = false;
    if (st[i].size() == n)
      ty2 = false;
  }
  if (ty1)
    cout << "pairwise coprime\\n";
  else if (ty2)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  sieve();
  int tests = 1;
  // cin>>tests;
  while (tests--) {
    test();
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front

using namespace std;
typedef long long int lli;
lli n, k, m, t, a, b, l, r, temp1, temp2, s, x, y, temp, q, d, mod = 1e9 + 7, w,
                                                               p, c;

lli gcd(lli a, lli b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
lli hashm[1000005];
lli spf[1000005];

void precalc() {
  spf[1] = 1;

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precalc();
  cin >> n;
  vector<lli> v(n);

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

    lli temp = v[i];

    set<lli> dis;

    while (spf[temp] > 1) {
      dis.insert(spf[temp]);
      temp = temp / spf[temp];
    }

    for (auto x : dis)
      hashm[x]++;
  }

  bool pairw = true, setwise = false;

  for (int i = 0; i < n; i++) {
    lli temp = v[i];

    set<lli> dis;

    while (spf[temp] > 1) {
      dis.insert(spf[temp]);
      temp = temp / spf[temp];
    }

    for (auto x : dis) {
      hashm[x]--;
    }

    for (auto x : dis) {
      if (hashm[x] >= 1)
        pairw = false;
    }

    if (!pairw)
      break;
  }

  lli temp = v[0];

  for (int i = 1; i < n; i++) {
    temp = gcd(temp, v[i]);
  }

  if (temp == 1)
    setwise = true;

  if (pairw) {
    cout << "pairwise coprime" << endl;
  } else if (setwise) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front

using namespace std;
typedef long long int lli;
lli n, k, m, t, a, b, l, r, temp1, temp2, s, x, y, temp, q, d, mod = 1e9 + 7, w,
                                                               p, c;

lli gcd(lli a, lli b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
lli hashm[1000005];
lli spf[1000005];

void precalc() {
  spf[1] = 1;

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precalc();
  cin >> n;
  vector<lli> v(n);

  for (int i = 0; i < n; i++) {
    cin >> v[i];
    hashm[v[i]]++;
  }

  bool pairw = true, setwise = false;

  for (int i = 0; i < n; i++) {
    lli temp = v[i];
    hashm[v[i]]--;
    set<lli> dis;

    while (spf[temp] > 1) {
      dis.insert(spf[temp]);
      temp = temp / spf[temp];
    }

    for (auto x : dis) {
      lli k = x;
      for (int j = x; j <= 1000000; j += x) {
        if (hashm[j] >= 1) {
          pairw = false;
        }
      }

      if (!pairw)
        break;
    }
  }

  lli temp = v[0];

  for (int i = 1; i < n; i++) {
    temp = gcd(temp, v[i]);
  }

  if (temp == 1)
    setwise = true;

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


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf = 1e6 + 9;
int n, a[inf];

bitset<inf> bs;
vector<int> primes;
int sieve_size, g;
void sieves() {
  sieve_size = 1e3;
  bs.set();
  bs[0] = bs[1] = 0;
  for (int i = 2; i <= sieve_size; i++) {
    if (bs[i]) {
      for (int j = i * i; j <= sieve_size; j += i)
        bs[j] = 0;
      primes.push_back((int)i);
    }
  }
}

bool valid[inf];

void check(int x) {
  if (valid[x]) {
    if (g == 1)
      puts("setwise coprime"), exit(0);
    else
      puts("not coprime"), exit(0);
  }
  valid[x] = 1;
}

int main() {
  sieves();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  g = a[1];
  for (int i = 2; i <= n; i++)
    g = __gcd(g, a[i]);

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

    for (auto o : primes) {
      if (o > a[i] || a[i] % o)
        continue;
      check(o);
      while ((a[i] % o) == 0)
        a[i] /= o;
    }
    if (a[i] != 1)
      check(a[i]);
  }
  puts("pairwise coprime");
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf = 1e6 + 9;
int n, a[inf];

bitset<inf> bs;
vector<int> primes;
int sieve_size, g;
void sieves() {
  sieve_size = inf / 2;
  bs.set();
  bs[0] = bs[1] = 0;
  for (int i = 2; i <= sieve_size; i++) {
    if (bs[i]) {
      for (int j = i * i; j <= sieve_size; j += i)
        bs[j] = 0;
      primes.push_back((int)i);
    }
  }
}

bool valid[inf];

void check(int x) {
  if (valid[x]) {
    if (g == 1)
      puts("setwise coprime"), exit(0);
    else
      puts("not coprime"), exit(0);
  }
  valid[x] = 1;
}

int main() {
  sieves();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  g = a[1];
  for (int i = 2; i <= n; i++)
    g = __gcd(g, a[i]);

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

    for (auto o : primes) {
      if (o > a[i] || a[i] % o)
        continue;
      check(o);
      while ((a[i] % o) == 0)
        a[i] /= o;
    }
    if (a[i] != 1)
      check(a[i]);
  }
  puts("pairwise coprime");
}