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

#include <algorithm>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimization("unroll-loops, no-stack-protector")
// #pragma GCC target("avx,avx2,fma")

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

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

  int MAXN = 1000100, n, i, j, k, g, ct;
  bool pairwise, setwise;

  cin >> n;
  vector<int> a(n);
  vector<int> used(MAXN, 0);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      g = a[i];
    else
      g = gcd(g, a[i]);
    used[a[i]]++;
  }

  pairwise = true;
  for (i = 2; i < MAXN; i++) {
    ct = 0;
    for (j = i; j < MAXN; j += i)
      ct += used[j];
    if (ct > 1)
      pairwise = false;
  }

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

  return 0;
}
/// from wiji

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> v;
set<int> pr;
bool vis[1000004];

void prime() {
  int x = sqrt(1000000);
  for (int i = 0; i < 1000005; i += 2) {
    vis[i] = true;
  }
  vis[2] = false;
  v.push_back(2);
  for (int i = 3; i <= x; i += 2) {
    if (!vis[i]) {
      v.push_back(i);
      for (int j = 2 * i; j < 100005; j += i) {
        if (!vis[j]) {
          vis[j] = true;
        }
      }
    }
  }
}

void solve() {
  prime();
  int n, i, j, k, cnt1 = 0, mx = -1;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      cnt1++;
    }
    mx = max(mx, a[i]);
  }

  memset(vis, 0, sizeof(vis));
  for (i = 0; i < n; i++) {
    if (v[i] > mx) {
      break;
    }
    for (j = 0; j < n; j++) {
      if (!vis[a[j]] && a[j] % v[i] == 0) {
        vis[a[j]] = true;
        pr.insert(v[i]);
      }
    }
  }
  if (cnt1 > 0) {
    if (n - cnt1 == pr.size()) {
      cout << "pairwise coprime" << endl;
    } else {
      cout << "setwise coprime" << endl;
    }
  } else {
    if (pr.size() == 1) {
      cout << "not coprime" << endl;
    } else if (pr.size() == n) {
      cout << "pairwise coprime" << endl;
    } else {
      cout << "setwise coprime" << endl;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const int maxn = 1e6;
int n;
int a[maxn + 5];
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int tot = 0;
bool used[maxn + 5];
int fen(int x) {
  int sqr = sqrt(x);
  for (int i = 2; i <= sqr; i++) {
    if (x % i == 0) {
      if (used[i])
        return 0;
      used[i] = 1;
    }
    while (x % i == 0) {
      x /= i;
    }
  }
  if (x != 1) {
    if (used[x])
      return 0;
    used[x] = 1;
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (!fen(a[i])) {
      ans = 0;
      break;
    }
  }
  if (ans == 1) {
    printf("pairwise coprime");
    return 0;
  }
  ans = a[1];
  for (int i = 2; i <= n; i++) {
    ans = gcd(ans, a[i]);
  }
  if (ans == 1) {
    printf("setwise coprime");
    return 0;
  }
  printf("not coprime");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const int maxn = 1e6;
int n;
int a[maxn + 5];
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int tot = 0;
bool isprime[maxn + 5];
int zhi[maxn + 5];
void getprime(int n) // 筛到n
{
  for (int i = 0; i < maxn; i++) {
    isprime[i] = 1;
  }
  isprime[1] = 0; // 1不是素数
  for (int i = 2; i <= n; i++) {
    if (isprime[i])   // 没筛掉
      zhi[++tot] = i; // i成为下一个素数
    for (int j = 1; j <= tot && i * zhi[j] <= n; j++) {
      isprime[i * zhi[j]] = 0;
      if (i % zhi[j] == 0)
        break;
    }
  }
}
int used[1000005];
int fen(int x) {
  for (int i = 1; i <= tot; i++) {
    if (x % zhi[i] == 0) {
      if (used[i])
        return 0;
      used[i] = 1;
    }
    while (x % zhi[i] == 0) {
      used[i] = 1;
      x /= zhi[i];
    }
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }

  //	cout<<"shai"<<endl;
  getprime(maxn);
  //	cout<<"shai done"<<endl;
  for (int i = 2; i <= n; i++) {
    if (isprime[i])
      zhi[++tot] = i;
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (!fen(a[i])) {
      ans = 0;
      break;
    }
  }
  if (ans == 1) {
    printf("pairwise coprime");
    return 0;
  }
  ans = a[1];
  for (int i = 2; i <= n; i++) {
    ans = gcd(ans, a[i]);
  }
  if (ans == 1) {
    printf("setwise coprime");
    return 0;
  }
  printf("not coprime");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  int n, b[1000010], a[1000010], i, j;
  cin >> n;
  int res = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  vector<int> c(1000010, 0);
  for (i = 0; i < n; i++) {
    for (j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (c[j] == 0) {
          c[j] = 1;
          while (a[i] % j == 0) {
            a[i] = a[i] / j;
          }
        } else {
          res = 1;
          break;
        }
      }
    }
    if (a[i] != 1) {
      if (c[a[i]] == 0) {
        c[a[i]] = 1;
      } else {
        res = 1;
        break;
      }
    }
    if (res == 1) {
      break;
    }
  }
  if (res == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    a[i] = b[i];
  }
  int q = gcd(a[0], a[1]);
  for (i = 2; i < n; i++) {
    q = gcd(q, a[i]);
  }
  if (q == 1) {
    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<int, int> P;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  int x[1000010], n, b[1000010], a[1000010], i, j;
  cin >> n;
  int res = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  vector<int> c(1010, 0);
  for (i = 0; i < n; i++) {
    for (j = 2; j * j <= b[i]; j++) {
      if (a[i] == 1) {
        break;
      }
      if (a[i] % j == 0) {
        if (c[j] == 0) {
          c[j] = 1;
          while (a[i] % j == 0) {
            a[i] = a[i] / j;
          }
        } else {
          res = 1;
          break;
        }
      }
    }
    if (a[i] != 1) {
      if (c[a[i]] == 0) {
        c[a[i]] = 1;
      } else {
        res = 1;
        break;
      }
    }
    if (res == 1) {
      break;
    }
  }
  if (res == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    a[i] = b[i];
  }
  int q = gcd(a[0], a[1]);
  for (i = 2; i < n; i++) {
    q = gcd(q, a[2]);
  }
  if (q == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

set<int> factors;

int n;

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

  bool coprime = true;

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (j != 1) {
          if (factors.find(j) != factors.end()) {
            coprime = false;
            break;
          }
          factors.insert(j);
        }
        int k = a[i] / j;
        if (k != 1 and j != k) {
          if (factors.find(k) != factors.end()) {
            coprime = false;
            break;
          }
          factors.insert(k);
        }
      }
    }
    if (!coprime)
      break;
  }

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

  int hcf = a[0];

  for (int i = 0; i < n; i++) {
    hcf = __gcd(hcf, a[i]);
  }

  if (hcf == 1) {
    cout << "setwise coprime";
    return;
  }

  cout << "not coprime";
}

int main() {
  sync;
  factors.clear();
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}


Error: WA

Fixed submission:

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

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

set<int> factors;

int n;

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

  bool coprime = true;

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (j != 1) {
          if (factors.find(j) != factors.end()) {
            coprime = false;
            break;
          }
          factors.insert(j);
        }
      }
      int k = a[i] / j;
      if (k != 1) {
        if (factors.find(k) != factors.end()) {
          coprime = false;
          break;
        }
        factors.insert(k);
      }
    }
    if (!coprime)
      break;
  }

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

  int hcf = a[0];

  for (int i = 0; i < n; i++) {
    hcf = __gcd(hcf, a[i]);
  }

  if (hcf == 1) {
    cout << "setwise coprime";
    return;
  }

  cout << "not coprime";
}

int main() {
  sync;
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

set<int> primes(ll n, bool flog = false) {
  int N = ((int)sqrt(n)) + 1;
  vector<bool> num(N, true);
  set<int> p;
  for (int i = 2; i < N; i++) {
    if (num[i]) {
      p.insert(i);
      if (flog)
        cout << "primes " << i << endl;
      for (int j = i; j < N; j += i) {
        num[j] = false;
      }
    }
  }
  return p;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  set<int> P = primes(1000000, false);

  bool pc = true;
  while (!P.empty()) {
    int p = *P.begin();
    P.erase(p);
    int score = 0;
    for (int i = 0; i < N; i++) {
      if ((A[i] % p) == 0) {
        A[i] /= p;
        score++;
      }
    }
    if (score == N) {
      cout << "not coprime" << endl;
      return (0);
    }
    if (score >= 2) {
      pc = false;
    }
  }

  int sss = 0;
  set<ll> SSS;
  for (int i = 0; i < N; i++) {
    if (A[i] > 1) {
      sss++;
      SSS.insert(A[i]);
    }
  }
  if (sss > SSS.size()) {
    pc = false;
  }
  if (SSS.size() == 1 && sss == N) {
    cout << "not coprime" << endl;
    return (0);
  }
  if (pc) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }
  return (0);
}


Error: TLE

Fixed submission:

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

set<int> primes(ll n, bool flog = false) {
  int N = ((int)sqrt(n)) + 1;
  vector<bool> num(N, true);
  set<int> p;
  for (int i = 2; i < N; i++) {
    if (num[i]) {
      p.insert(i);
      if (flog)
        cout << "primes " << i << endl;
      for (int j = i; j < N; j += i) {
        num[j] = false;
      }
    }
  }
  return p;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  set<int> P = primes(1000000, false);

  bool pc = true;
  while (!P.empty()) {
    int p = *P.begin();
    P.erase(p);
    int score = 0;
    for (int i = 0; i < N; i++) {
      if ((A[i] % p) == 0) {
        A[i] /= p;
        score++;
      }
    }
    if (score == N) {
      cout << "not coprime" << endl;
      return (0);
    }
    if (score >= 2) {
      pc = false;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] > 1) {
      P.insert(A[i]);
    }
  }
  while (!P.empty()) {
    int p = *P.begin();
    P.erase(p);
    int score = 0;
    for (int i = 0; i < N; i++) {
      if ((A[i] % p) == 0) {
        A[i] /= p;
        score++;
      }
    }
    if (score == N) {
      cout << "not coprime" << endl;
      return (0);
    }
    if (score >= 2) {
      pc = false;
    }
  }
  if (pc) {
    cout << "pairwise coprime" << endl;
  } else {
    cout << "setwise coprime" << endl;
  }
  return (0);
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

const int N = 1e6 + 5;
vector<int> val;
vector<int> v(N);
int n;

void solve() {
  int gcd = 0;
  for (int i : val) {
    v[i]++;
    gcd = __gcd(gcd, i);
  }

  if (gcd != 1) {
    cout << "not coprime\\n";
    return;
  }

  for (int i = 2; i < N; i++) {
    for (int j = i + i; j < N; j += i)
      v[i] += v[j];

    if (v[i] > 1) {
      cout << "setwise coprime\\n";
      return;
    }
  }

  cout << "pairwise coprime\\n";
}

int main() {
  fast();
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    val.pb(a);
  }
  solve();
}

Error: TLE

Fixed submission:

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

int prime[1000005];

void pre() {
  memset(prime, -1, sizeof(prime));
  prime[0] = 0;
  prime[1] = 1;
  for (int i = 2; i <= 1000000; i++) {
    if (prime[i] == -1) {
      prime[i] = i;
      for (int j = i * i; j <= 1000000; j += i) {
        if (prime[j] == -1)
          prime[j] = i;
      }
    }
  }
}
void solve() {
  for (int i = 1; i <= 1000000; i++) {
    if (prime[i] == -1)
      prime[i] = i;
  }
  int n;
  cin >> n;
  vector<int> arr(n);

  // set<int>st;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    // st.insert(prime[arr[i]]);
  }
  int g = arr[0];
  for (int i = 1; i < n; i++)
    g = __gcd(g, arr[i]);

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (__gcd(arr[i], arr[j]) != 1) {
        flag = 1;
        break;
      }
    }
  }
  // cout<<g<<endl;

  // if((int)st.size()==n)
  if (flag == 0)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
int32_t main() {
  pre();
  rapido;
  int t;
  t = 1;
  while (t--)
    solve();
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

const int MAX = 1e6;
vector<int> prime(MAX + 1, -1);

void settable() {
  for (int i = 2; i <= MAX; i++) {
    if (prime[i] == -1) {
      prime[i] = i;
      for (int j = i + i; j <= MAX; j += i) {
        prime[j] = i;
      }
    }
  }
}

int main() {
  settable();
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> ok(MAX + 1, false);
  bool ok1 = true, ok2 = true;
  for (int i = 0; i < n; i++) {
    int nn = a[i];
    if (nn == 1)
      continue;
    set<int> s;
    do {
      int d = prime[nn];
      s.insert(d);
      nn /= d;
    } while (nn > 1);

    for (auto dd : s) {
      if (ok[dd])
        ok1 = false;
      ok[dd] = true;
    }
  }

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

Error: 0

Fixed submission:

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

template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

const int MAX = 1e6;
vector<int> prime(MAX + 1, -1);

void settable() {
  for (int i = 2; i <= MAX; i++) {
    if (prime[i] == -1) {
      prime[i] = i;
      for (int j = i + i; j <= MAX; j += i) {
        prime[j] = i;
      }
    }
  }
}

int main() {
  settable();
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> ok(MAX + 1, false);
  bool ok1 = true, ok2 = true;
  for (int i = 0; i < n; i++) {
    int nn = a[i];
    set<int> s;
    do {
      int d = prime[nn];
      s.insert(d);
      nn /= d;
    } while (nn > 1);

    for (auto dd : s) {
      if (ok[dd])
        ok1 = false;
      ok[dd] = true;
    }
  }

  int G = 0;
  for (int i = 0; i < n; i++) {
    G = gcd(a[i], G);
  }
  ok2 = (G == 1);
  if (ok1) {
    cout << "pairwise coprime" << endl;
  } else if (ok2) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
// https://atcoder.jp/contests/abc177/tasks/abc177_e
ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string ans[] = {"pairwise coprime", "setwise coprime", "not coprime"};
  ll n;
  cin >> n;
  vector<ll> v(1010101);
  vector<ll> num(1010101);
  ll g = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    g = gcd(g, v[i]);
    num[v[i]]++;
  }
  ll val = -1;
  int i;
  for (i = 2; i <= 1000000; i++) {
    ll x = 0;
    for (int j = i; j <= 1000000; j += i) {
      x += num[j];
    }
    if (x >= 2)
      break;
  }
  if (i == 1000001)
    val = 0;
  else if (g == 1)
    val = 1;
  else
    val = 2;
  cout << ans[val];

  return 0;
}

Error: -11

Fixed submission:

#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
// https://atcoder.jp/contests/abc177/tasks/abc177_e
ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string ans[] = {"pairwise coprime", "setwise coprime", "not coprime"};
  ll n;
  cin >> n;
  vector<ll> v(n + 1);
  vector<ll> num(n + 1);
  ll g = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    g = gcd(g, v[i]);
    num[v[i]]++;
  }
  ll val = -1;
  int i;
  for (i = 2; i <= 1000000; i++) {
    ll x = 0;
    for (int j = i; j <= 100000; j += i) {
      x += num[j];
    }
    if (x >= 2)
      break;
  }
  if (i == 1000001)
    val = 0;
  else if (g == 1)
    val = 1;
  else
    val = 2;
  cout << ans[val];

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

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

using ll = long long;
using pi = pair<int, int>;

const int maxn = 1e6 + 5;

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

  vector<bool> is_prime(maxn, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= maxn; i++) {
    if (is_prime[i] && (ll)i * i <= maxn) {
      for (int j = i * i; j <= maxn; j += i)
        is_prime[j] = false;
    }
  }

  vector<int> primes;
  for (int i = 2; i <= maxn; i++) {
    if (is_prime[i])
      primes.push_back(i);
  }

  vector<bool> found(maxn, false);
  int n, all = 0, flag = 1;
  cin >> n;
  while (n--) {
    int num;
    cin >> num;
    if (all == 0)
      all = num;
    else
      all = __gcd(all, num);
    for (ll p : primes) {
      if (p * p > num)
        break;
      int count = 0;
      while (num % p == 0) {
        count++;
        num /= p;
      }
      if (count > 0) {
        if (found[p])
          flag = 0;
        else
          found[p] = true;
      }
    }
    if (num > 1) {
      if (found[num])
        flag = 0;
      else
        found[num] = true;
    }
  }

  if (flag == 1)
    cout << "pairwise coprime" << endl;
  else if (all == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}

Error: 0

Fixed submission:

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

using ll = long long;
using pi = pair<int, int>;

const int maxn = 1e3 + 5;

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

  vector<bool> is_prime(maxn, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= maxn; i++) {
    if (is_prime[i] && (ll)i * i <= maxn) {
      for (int j = i * i; j <= maxn; j += i)
        is_prime[j] = false;
    }
  }

  vector<int> primes;
  for (int i = 2; i <= maxn; i++) {
    if (is_prime[i])
      primes.push_back(i);
  }

  vector<bool> found(maxn, false);
  int n, all = 0, flag = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    if (all == 0)
      all = num;
    else
      all = __gcd(all, num);
    for (int p : primes) {
      if (p * p > num)
        break;
      int count = 0;
      while (num % p == 0) {
        count++;
        num /= p;
      }
      if (count > 0) {
        if (found[p])
          flag = 0;
        else
          found[p] = true;
        // cout << p << " ";
      }
    }
    if (num > 1) {
      if (found[num])
        flag = 0;
      else
        found[num] = true;
    }
    // cout << all << " " << flag << endl;
  }

  if (flag == 1)
    cout << "pairwise coprime" << endl;
  else if (all == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}