prithivMLmods/Coder-Stat huggingface dataset:
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <set>

// 素因数分解　
// pair<ll,ll>型
// auto pf=prime_factorize(ll N);で呼ぶ
// for(auto p:pf){}で探す

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
const int K = 100005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(K);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool ok = true;
  for (int i = 2; i < K; ++i) {
    int cnt = 0;
    for (int j = i; j < K; j += i) {
      cnt += c[j];
    }
    if (cnt >= 2)
      ok = false;
  }

  if (ok) {
    cout << "pairwise coprime";
    return 0;
  }
  int k = a[0];
  rep(i, n) { k = gcd(a[i], k); }
  if (k == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <set>

// 素因数分解　
// pair<ll,ll>型
// auto pf=prime_factorize(ll N);で呼ぶ
// for(auto p:pf){}で探す

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
const int K = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(K);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool ok = true;
  for (int i = 2; i < K; ++i) {
    int cnt = 0;
    for (int j = i; j < K; j += i) {
      cnt += c[j];
    }
    if (cnt >= 2)
      ok = false;
  }

  if (ok) {
    cout << "pairwise coprime";
    return 0;
  }
  int k = a[0];
  rep(i, n) { k = gcd(a[i], k); }
  if (k == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
from math import gcd


N = int(input())
A = list(map(int, input().split()))

# setwise validation
tmp = 0
for a in A:
    tmp = gcd(tmp, a)
isSetwise = tmp == 1


# pairwise validation
M = 10**6
A = set(A)
isPairwise = True
for i in range(2, M):
    cnt = 0
    ni = 0
    while (ni := ni + i) <= M:
        cnt += ni in A
    isPairwise &= cnt <= 1

# check
if isPairwise:
    ans = "pairwise coprime"
elif isSetwise:
    ans = "setwise coprime"
else:
    ans = "not coprime"
print(ans)


Fixed submission:
from math import gcd


N = int(input())
A = list(map(int, input().split()))

# setwise validation
tmp = 0
for a in A:
    tmp = gcd(tmp, a)
isSetwise = tmp == 1


# pairwise validation
M = 10**6
sieve = [0] * (M + 1)
for a in A:
    sieve[a] += 1

cnt = 0
for i in range(2, M + 1):
    cnt = max(cnt, sum(sieve[j] for j in range(i, M + 1, i)))
isPairwise = cnt <= 1

# check
if isPairwise:
    ans = "pairwise coprime"
elif isSetwise:
    ans = "setwise coprime"
else:
    ans = "not coprime"
print(ans)
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

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

int main() {
  int n, x, flag, flag2 = 1;
  cin >> n;
  vector<int> a(n);
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n && flag2 == 1; i++) {
    x = a[i];
    for (int j = 2; j <= 1000; j++) {
      flag = 0;
      while (x % j == 0) {
        x /= j;
        flag = 1;
      }
      if (flag && s.find(j) == s.end()) {
        s.insert(j);
      } else if (flag) {
        flag2 = 0;
        break;
      }
    }
    if (x != 1 && s.find(x) == s.end()) {
      s.insert(x);
    } else if (x != 1) {
      flag2 = 0;
      break;
    }
  }
  if (flag2 == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  for (int i = 0; i < n; i++) {
    g = gcd(g, a[i]);
  }
  cout << (g == 1 ? "setwise coprime" : "not coprime") << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

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

int main() {
  int n, x, flag, flag2 = 1;
  cin >> n;
  vector<int> a(n);
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n && flag2 == 1; i++) {
    x = a[i];
    for (int j = 2; j <= 1000 && x != 1; j++) {
      flag = 0;
      while (x % j == 0) {
        x /= j;
        flag = 1;
      }
      if (flag && s.find(j) == s.end()) {
        s.insert(j);
      } else if (flag) {
        flag2 = 0;
        break;
      }
    }
    if (x != 1 && s.find(x) == s.end()) {
      s.insert(x);
    } else if (x != 1) {
      flag2 = 0;
      break;
    }
  }
  if (flag2 == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  for (int i = 0; i < n; i++) {
    g = gcd(g, a[i]);
  }
  cout << (g == 1 ? "setwise coprime" : "not coprime") << endl;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define ma 1000005

ll gcd(ll, ll);

int main() {
  ll n;
  ll x;
  ll gc = 0;
  bool pc = true;
  cin >> n;
  vector<ll> a(n);
  vector<ll> c(ma);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }
  for (ll i = 2; i < ma; i++) {
    int count = 0;
    for (ll j = i; j < ma; j += i) {
      count += c[j];
    }
    if (count > 1) {
      pc = false;
    }
  }
  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  rep(i, n) gc = gcd(gc, a[i]);

  if (gc == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}

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


Fixed submission:
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define ma 1000005

ll gcd(ll, ll);

int main() {
  ll n;
  ll x;
  ll gc = 0;
  bool pc = true;
  cin >> n;
  vector<ll> a(n);
  vector<ll> c(ma);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }
  for (ll i = 2; i < ma; i++) {
    int count = 0;
    for (ll j = i; j < ma; j += i) {
      count += c[j];
    }
    if (count > 1) {
      pc = false;
    }
  }
  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  rep(i, n) gc = gcd(gc, a[i]);

  if (gc == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1e6;
bool is_prime[N + 5];
int d[N + 5]; // d[i]=iの最小の素因数
int mp[N + 5];
int main() {
  for (int i = 0; i < N; i++)
    is_prime[i] = true; // エラトステネス
  for (int i = 2; i < N; i++) {
    if (is_prime[i])
      d[i] = i;
    for (int j = i + i; j < N; j += i) {
      is_prime[j] = false;
      if (is_prime[i] && d[j] == 0)
        d[j] = i;
    }
  }

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> p;
  for (int i = 0; i < n; i++) {
    while (a[i] > 1) {
      int m = d[a[i]];
      a[i] /= m;
      if (a[i] % m != 0)
        p.push_back(m);
    }
  }
  for (auto x : p)
    mp[x]++;
  int ans = 0;
  for (int i = 1; i < N + 5; i++) {
    if (mp[i] >= 2 && mp[i] <= n - 1)
      ans = 1;
    if (mp[i] == n) {
      ans = 2;
      break;
    }
  }
  if (ans == 0)
    cout << "pairwise coprime" << endl;
  if (ans == 1)
    cout << "setwise coprime" << endl;
  if (ans == 2)
    cout << "not coprime" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1000005;
bool is_prime[N + 5];
int d[N + 5]; // d[i]=iの最小の素因数
int mp[N + 5];
int main() {
  for (int i = 0; i < N; i++)
    is_prime[i] = true; // エラトステネス
  for (int i = 2; i < N; i++) {
    if (is_prime[i])
      d[i] = i;
    for (int j = i + i; j < N; j += i) {
      is_prime[j] = false;
      if (is_prime[i] && d[j] == 0)
        d[j] = i;
    }
  }

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> p;
  for (int i = 0; i < n; i++) {
    while (a[i] > 1) {
      int m = d[a[i]];
      a[i] /= m;
      if (a[i] % m != 0)
        p.push_back(m);
    }
  }
  for (auto x : p)
    mp[x]++;
  int ans = 0;
  for (int i = 1; i < N + 5; i++) {
    if (mp[i] >= 2 && mp[i] <= n - 1)
      ans = 1;
    if (mp[i] == n) {
      ans = 2;
      break;
    }
  }
  if (ans == 0)
    cout << "pairwise coprime" << endl;
  if (ans == 1)
    cout << "setwise coprime" << endl;
  if (ans == 2)
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL n;
  cin >> n;

  vector<LL> a(n);

  for (auto &e : a) {
    cin >> e;
  }

  LL net_gcd = a[0];
  for (LL i = 1; i < n; ++i) {
    net_gcd = __gcd(net_gcd, a[i]);
  }

  if (net_gcd != 1) {
    cout << "not coprime\n";
    return 0;
  }
  vector<LL> primes(N, 0);
  for (LL i = 0; i < n; ++i) {
    LL x = a[i];

    for (LL j = 2; j * j <= a[i]; ++j) {
      if (x % j == 0) {
        while (x % j == 0)
          x /= j;
        primes[j]++;
      }
    }
    if (x > 1) {
      primes[x]++;
    }
  }

  for (auto e : primes) {
    if (e > 1) {
      cout << "setwise coprime\n";
      return 0;
    }
  }
  cout << "pairwise coprime\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL n;
  cin >> n;

  vector<LL> a(n);

  for (auto &e : a) {
    cin >> e;
  }

  LL net_gcd = a[0];
  for (LL i = 1; i < n; ++i) {
    net_gcd = __gcd(net_gcd, a[i]);
  }

  if (net_gcd != 1) {
    cout << "not coprime\n";
    return 0;
  }
  vector<LL> primes(N, 0);
  for (LL i = 0; i < n; ++i) {
    LL x = a[i];

    for (LL j = 2; j * j <= x; ++j) {
      if (x % j == 0) {
        while (x % j == 0)
          x /= j;
        primes[j]++;
      }
    }
    if (x > 1) {
      primes[x]++;
    }
  }

  for (auto e : primes) {
    if (e > 1) {
      cout << "setwise coprime\n";
      return 0;
    }
  }
  cout << "pairwise coprime\n";

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
using namespace std;

const int maxn = 10050;
const int maxm = 1000050;
ll p[maxm], a[maxm], s[maxm], cnt = 0;
bool vis[maxm];

void init() {
  for (int i = 2; i < maxn; ++i) {
    if (!vis[i])
      p[cnt++] = i;
    for (int j = 0; j < cnt && p[j] * i < maxn; ++j) {
      vis[p[j] * i] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
int main() {
  init();
  int n, mx = 0;
  cin >> n;
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x > mx)
      mx = x;
    for (int j = 0; j < cnt; ++j)
      if (x % p[j] == 0) {
        s[p[j]]++;
        while (x % p[j] == 0) {
          x /= p[j];
        }
      }
    if (x > 1)
      s[x]++;
  }
  int f1 = 1, f2 = 1;
  for (int i = 1; i < mx; ++i) {
    if (s[i] > 1)
      f1 = 0;
    if (s[i] == n)
      f2 = 0;
  }
  if (f1) {
    cout << "pairwise coprime" << endl;
  } else {
    if (f2) {
      cout << "setwise coprime" << endl;
    } else
      cout << "not coprime" << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
using namespace std;

const int maxn = 1020;
const int maxm = 1000050;
ll p[maxm], a[maxm], s[maxm], cnt = 0;
bool vis[maxm];

void init() {
  for (int i = 2; i < maxn; ++i) {
    if (!vis[i])
      p[cnt++] = i;
    for (int j = 0; j < cnt && p[j] * i < maxn; ++j) {
      vis[p[j] * i] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
int main() {
  init();
  int n, mx = 0;
  cin >> n;
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x > mx)
      mx = x;
    for (int j = 0; j < cnt; ++j)
      if (x % p[j] == 0) {
        s[p[j]]++;
        while (x % p[j] == 0) {
          x /= p[j];
        }
      }
    if (x > 1)
      s[x]++;
  }
  int f1 = 1, f2 = 1;
  for (int i = 1; i < mx; ++i) {
    if (s[i] > 1)
      f1 = 0;
    if (s[i] == n)
      f2 = 0;
  }
  if (f1) {
    cout << "pairwise coprime" << endl;
  } else {
    if (f2) {
      cout << "setwise coprime" << endl;
    } else
      cout << "not coprime" << endl;
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
int main() {
  int N, ans, i;
  cin >> N;
  int A[N];
  REP(i, N) cin >> A[i];
  ans = A[0];
  REP(i, N - 1) ans = __gcd(ans, A[i + 1]);
  if (ans == 1) {
    int x = 1;
    vector<int> X;
    REP(i, N) {
      int j = 1;
      while (A[i] != 1) {
        j++;
        if (j * j > A[i]) {
          X.push_back(A[i]);
          break;
        }
        if (A[i] % j == 0) {
          X.push_back(j);
          while (A[i] % j == 0)
            A[i] /= j;
        }
      }
      if (X.size() > 78498)
        break;
    }
    sort(ALL(X));
    REP(i, X.size() - 1) if (X.at(i) == X.at(i + 1)) x = 0;
    if (x == 1)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
int main() {
  int N, ans, i;
  cin >> N;
  int A[N];
  REP(i, N) cin >> A[i];
  ans = A[0];
  REP(i, N - 1) ans = __gcd(ans, A[i + 1]);
  if (ans == 1) {
    int x = 1;
    vector<int> X;
    REP(i, N) {
      int j = 1;
      while (A[i] != 1) {
        j++;
        if (j * j > A[i]) {
          X.push_back(A[i]);
          break;
        }
        if (A[i] % j == 0) {
          X.push_back(j);
          while (A[i] % j == 0)
            A[i] /= j;
        }
      }
      if (X.size() > 78498)
        break;
    }
    if (X.size())
      sort(ALL(X));
    if (X.size() > 1)
      REP(i, X.size() - 1) if (X.at(i) == X.at(i + 1)) x = 0;
    if (x == 1)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
const ll MOD = 9998903;

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

void solve() {
  ll i, j, count;
  ll N;
  cin >> N;
  vector<ll> A(N, 0);
  vector<ll> exist(100100, 0);
  ll gcd = 0;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    gcd = GCD(gcd, A[i]);
    exist[A[i]]++;
  }
  for (i = 2; i <= 1000000; i++) {
    count = 0;
    for (j = i; j <= 1000000; j += i)
      count += exist[j];
    if (count >= 2)
      break; // 被りがあったら
  }
  if (i == 1000001) { // 被りがなければiは1000001となる
    cout << "pairwise coprime" << endl;
    return;
  }
  if (gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

int main() {
  solve();
  return 0;
}

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
const ll MOD = 9998903;

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

void solve() {
  ll i, j, count;
  ll N;
  cin >> N;
  vector<ll> A(N, 0);
  vector<ll> exist(1001000, 0);
  ll gcd = 0;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    gcd = GCD(gcd, A[i]);
    exist[A[i]]++;
  }
  for (i = 2; i <= 1000000; i++) {
    count = 0;
    for (j = i; j <= 1000000; j += i)
      count += exist[j];
    if (count >= 2)
      break; // 被りがあったら
  }
  if (i == 1000001) { // 被りがなければiは1000001となる
    cout << "pairwise coprime" << endl;
    return;
  }
  if (gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

int main() {
  solve();
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp, t, n, j, a[200600], ans, g, C[200010];
bool cond;
char c;
string s;
void solve(ll x) {
  if (cond)
    return;
  for (j = 1; j * j <= x; j++) {
    if (x % j == 0) {
      ll a = j;
      ll b = x / j;
      if (a == b) {
        a = j;
        b = 1;
      }
      if (a != 1) {
        if (C[a]) {
          cond = true;
          //  cout << "Here 1  " << a <<endl;
          return;
        }
        C[a]++;
        // cout << "a = "<< a << endl;
      }
      if (b != 1) {
        if (C[b]) {
          cond = true;
          // cout << "Here 2" <<" "<< b <<" "<<x <<" "<<C[b]<<endl;
          return;
        }
        C[b]++;
        // cout << "b = " << b << endl;
      }
    }
  }
}
int main() {
  // I am Monim, a tiny creature of Allah
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  g = a[0];
  solve(a[0]);
  for (i = 1; i < n; i++) {
    solve(a[i]);
    g = __gcd(g, a[i]);
  }
  if (!cond)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp, t, n, j, a[2000010], ans, g, C[2000010];
bool cond;
char c;
string s;
void solve(ll x) {
  if (cond)
    return;
  for (j = 1; j * j <= x; j++) {
    if (x % j == 0) {
      ll a = j;
      ll b = x / j;
      if (a == b) {
        a = j;
        b = 1;
      }
      if (a != 1) {
        if (C[a]) {
          cond = true;
          //  cout << "Here 1  " << a <<endl;
          return;
        }
        C[a]++;
        // cout << "a = "<< a << endl;
      }
      if (b != 1) {
        if (C[b]) {
          cond = true;
          // cout << "Here 2" <<" "<< b <<" "<<x <<" "<<C[b]<<endl;
          return;
        }
        C[b]++;
        // cout << "b = " << b << endl;
      }
    }
  }
}
int main() {
  // I am Monim, a tiny creature of Allah
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  g = a[0];
  solve(a[0]);
  for (i = 1; i < n; i++) {
    solve(a[i]);
    g = __gcd(g, a[i]);
  }
  if (!cond)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i * i < n; ++i) {
    if (res[i] < i)
      continue;
    for (int j = i * i; j < n; j += i)
      if (res[j] == j)
        res[j] = i;
  }
  return res;
}

void factorize(long long n, vector<int> &prime_cnt, vector<int> &min_factor) {
  int p;
  while (n > 1) {
    p = min_factor[n];
    n /= p;
    if (min_factor[n] != p) {
      prime_cnt[p]++;
    }
  }
}

int main() {
  int N;
  cin >> N;

  vector<int> A(N);

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

  vector<int> prime_cnt;
  vector<int> prime_list = sieve(1e6);

  prime_cnt.assign(1e6, 0);

  for (int i = 0; i < N; i++) {
    if (A[i] != 1) {
      factorize(A[i], prime_cnt, prime_list);
    }
  }

  bool pw_cp = true;
  bool st_cp = true;

  for (auto val : prime_cnt) {
    if (val == 0)
      continue;
    if (val != 1) {
      pw_cp = false;
    }
    if (val == N) {
      st_cp = false;
    }
  }

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

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i * i < n; ++i) {
    if (res[i] < i)
      continue;
    for (int j = i * i; j < n; j += i)
      if (res[j] == j)
        res[j] = i;
  }
  return res;
}

void factorize(long long n, vector<int> &prime_cnt, vector<int> &min_factor) {
  int p;
  while (n > 1) {
    p = min_factor[n];
    n /= p;
    if (min_factor[n] != p) {
      prime_cnt[p]++;
    }
  }
}

int main() {
  int N;
  cin >> N;

  vector<int> A(N);

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

  vector<int> prime_cnt;
  vector<int> prime_list = sieve(1e6 + 1);

  prime_cnt.assign(1e6, 0);

  for (int i = 0; i < N; i++) {
    if (A[i] != 1) {
      factorize(A[i], prime_cnt, prime_list);
    }
  }

  bool pw_cp = true;
  bool st_cp = true;

  for (auto val : prime_cnt) {
    if (val == 0)
      continue;
    if (val != 1) {
      pw_cp = false;
    }
    if (val == N) {
      st_cp = false;
    }
  }

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

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;

ll n, a[1000005], x;
set<ll> myset;
bool f = true;
bool is_prime(ll x) {
  if (x <= 1)
    return false;
  for (ll i = 2; i <= (ll)sqrt(x); ++i)
    if (x % i == 0)
      return false;
  return true;
}
void factorize(ll x) {
  ll tec = 1;
  if (is_prime(x)) {
    if (myset.find(x) != myset.end())
      f = false;
    myset.insert(x);
    return;
  }
  bool flag;
  while (x > 1) {
    ++tec;
    flag = false;
    while (x % tec == 0) {
      flag = true;
      x /= tec;
    }
    if (flag) {
      if (myset.find(tec) != myset.end())
        f = false;
      myset.insert(tec);
      if (is_prime(x)) {
        if (myset.find(x) != myset.end())
          f = false;
        myset.insert(x);
        return;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (ll i = 1; i <= n; ++i)
    cin >> a[i];
  x = a[1];
  for (ll i = 2; i <= n; ++i) {
    x = __gcd(a[i], x);
  }
  for (ll i = 1; i <= n; ++i)
    factorize(a[i]);
  if (f) {
    cout << "pairwise coprime";
    return 0;
  }
  if (!f && x == 1) {
    cout << "setwise coprime";
    return 0;
  }
  cout << "not coprime";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;

ll n, a[1000005], x;
set<ll> myset;
bool f = true;
bool is_prime(ll x) {
  if (x <= 1)
    return false;
  for (ll i = 2; i <= (ll)sqrt(x); ++i)
    if (x % i == 0)
      return false;
  return true;
}
void factorize(ll x) {
  if (!f)
    return;
  ll tec = 1;
  if (is_prime(x)) {
    if (myset.find(x) != myset.end())
      f = false;
    myset.insert(x);
    return;
  }
  bool flag;
  while (x > 1) {
    ++tec;
    flag = false;
    while (x % tec == 0) {
      flag = true;
      x /= tec;
    }
    if (flag) {
      if (myset.find(tec) != myset.end())
        f = false;
      myset.insert(tec);
      if (is_prime(x)) {
        if (myset.find(x) != myset.end())
          f = false;
        myset.insert(x);
        return;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (ll i = 1; i <= n; ++i)
    cin >> a[i];
  x = a[1];
  for (ll i = 2; i <= n; ++i) {
    x = __gcd(a[i], x);
  }
  for (ll i = 1; i <= n; ++i)
    factorize(a[i]);
  if (f) {
    cout << "pairwise coprime";
    return 0;
  }
  if (!f && x == 1) {
    cout << "setwise coprime";
    return 0;
  }
  cout << "not coprime";
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int base = 31337;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n;
int a[maxn];
int bio[maxm + 20];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);

  for (int i = 0; i < n; i++)
    bio[a[i]]++;

  bool flag = true;
  for (int i = 2; i < maxm; i++) {
    int cnt = 0;
    for (int j = i; j < maxm; j += i)
      cnt += bio[j];
    if (cnt > 1) {
      flag = false;
      break;
    }
  }
  if (flag) {
    printf("pairwise coprime");
    return 0;
  }

  flag = true;
  for (int i = 2; i < maxm; i++) {
    int cnt = 0;
    for (int j = i; j < maxm; j += i)
      cnt += bio[j];
    if (cnt == n) {
      flag = false;
      break;
    }
  }

  if (flag) {
    printf("setwise coprime");
  } else
    printf("not coprime");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 1e6 + 10;
const int maxm = 1e6 + 10;
const int base = 31337;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n;
int a[maxn];
int bio[maxm + 20];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);

  for (int i = 0; i < n; i++)
    bio[a[i]]++;

  bool flag = true;
  for (int i = 2; i < maxm; i++) {
    int cnt = 0;
    for (int j = i; j < maxm; j += i)
      cnt += bio[j];
    if (cnt > 1) {
      flag = false;
      break;
    }
  }
  if (flag) {
    printf("pairwise coprime");
    return 0;
  }

  flag = true;
  for (int i = 2; i < maxm; i++) {
    int cnt = 0;
    for (int j = i; j < maxm; j += i)
      cnt += bio[j];
    if (cnt == n) {
      flag = false;
      break;
    }
  }

  if (flag) {
    printf("setwise coprime");
  } else
    printf("not coprime");
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

const int N = 1e6 + 5;

unordered_map<int, int> prcnt;
int lp[N], n, vvod, pair_copr, set_copr;
vector<int> pr, lispr, mas;

void fact(int chis) {
  if (chis <= 1) {
    return;
  }

  lispr.push_back(lp[chis]);

  fact(chis / lp[chis]);
}

int main() {
  ios_base::sync_with_stdio(0);
  // freopen( "input.txt", "r", stdin );

  for (int i = 2; i <= N; i++) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }

    for (int j = 0; j < int(pr.size()) && pr[j] <= lp[i] && i * pr[j] <= N;
         j++) {
      lp[i * pr[j]] = pr[j];
    }
  }

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> vvod;

    mas.push_back(vvod);
  }

  for (auto i : mas) {
    lispr = {};
    fact(i);
    prcnt[lispr[0]]++;
    for (int j = 0; j < int(lispr.size()) - 1; j++) {
      if (lispr[j + 1] != lispr[j]) {
        prcnt[lispr[j + 1]]++;
      }
    }
  }

  for (auto i : prcnt) {
    if (i.s > 1) {
      pair_copr = 1;
    }

    if (i.s == n) {
      set_copr = 1;
    }
  }

  if (!pair_copr) {
    cout << "pairwise coprime";
  } else {
    if (!set_copr) {
      cout << "setwise coprime";
    } else {
      cout << "not coprime";
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

const int N = 1e6 + 5;

unordered_map<int, int> prcnt;
int lp[N], n, vvod, pair_copr, set_copr;
vector<int> pr, lispr, mas;

void fact(int chis) {
  if (chis <= 1) {
    return;
  }

  lispr.push_back(lp[chis]);

  fact(chis / lp[chis]);
}

int main() {
  ios_base::sync_with_stdio(0);
  // freopen( "input.txt", "r", stdin );

  for (int i = 2; i <= N; i++) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }

    for (int j = 0; j < int(pr.size()) && pr[j] <= lp[i] && i * pr[j] <= N;
         j++) {
      lp[i * pr[j]] = pr[j];
    }
  }

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> vvod;

    mas.push_back(vvod);
  }

  for (auto i : mas) {
    lispr = {};
    fact(i);
    if (lispr.size()) {
      prcnt[lispr[0]]++;
      for (int j = 0; j < int(lispr.size()) - 1; j++) {
        if (lispr[j + 1] != lispr[j]) {
          prcnt[lispr[j + 1]]++;
        }
      }
    }
  }

  for (auto i : prcnt) {
    if (i.s > 1) {
      pair_copr = 1;
    }

    if (i.s == n) {
      set_copr = 1;
    }
  }

  if (!pair_copr) {
    cout << "pairwise coprime";
  } else {
    if (!set_copr) {
      cout << "setwise coprime";
    } else {
      cout << "not coprime";
    }
  }

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}

map<lint, int> p_factorization(lint n) {
  map<lint, int> soinsu;
  for (int i = 2; i <= sqrt(n); i++) {
    while (n % i == 0) {
      n /= i;
      soinsu[i]++;
    }
  }
  if (n != 1)
    soinsu[n]++;
  return soinsu;
}

// AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main() {
  bool pairwise = true;
  vector<int> vec(1000000);
  int n, x, tmp;
  cin >> n;
  cin >> tmp;
  map<lint, int> dic = p_factorization(tmp);
  for (auto p : dic) {
    vec[p.first] = 1;
  }
  for (int i = 1; i < n; i++) {
    cin >> x;
    tmp = __gcd(tmp, x);
    map<lint, int> dic = p_factorization(x);
    if (!pairwise)
      continue;
    for (auto p : dic) {
      if (vec[p.first] == 1) {
        pairwise = false;
      }
      vec[p.first] = 1;
    }
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (tmp == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}

map<lint, int> p_factorization(lint n) {
  map<lint, int> soinsu;
  for (int i = 2; i <= sqrt(n); i++) {
    while (n % i == 0) {
      n /= i;
      soinsu[i]++;
    }
  }
  if (n != 1)
    soinsu[n]++;
  return soinsu;
}

// AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  bool pairwise = true;
  vector<int> vec(1000000);
  int n, x, tmp;
  cin >> n;
  cin >> tmp;
  map<lint, int> dic = p_factorization(tmp);
  for (auto p : dic) {
    vec[p.first] = 1;
  }
  for (int i = 1; i < n; i++) {
    cin >> x;
    tmp = __gcd(tmp, x);
    map<lint, int> dic = p_factorization(x);
    if (!pairwise)
      continue;
    for (auto p : dic) {
      if (vec[p.first] == 1) {
        pairwise = false;
      }
      vec[p.first] = 1;
    }
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (tmp == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
from math import gcd


def eratosthenes(n):
    prime = []
    data = [i for i in range(n - 1)]
    while True:
        p = data[0]
        if n <= p**2:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return data


def factorize(N):  # 素因数分解
    prime = set()
    for p in prime_list:
        if p * p > N:
            break
        while N % p == 0:
            N //= p
            prime.add(p)
    if N > 1:
        prime.add(N)
    return prime


n = int(input())
a = list(map(int, input().split()))

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print("not coprime")
    exit()

prime_list = eratosthenes(10**6)
num = set()
for ai in a:
    prime = factorize(ai)
    if len(prime & num) > 0:
        print("setwise coprime")
        break
    num |= prime
else:
    print("pairwise coprime")


Fixed submission:
from math import gcd


def eratosthenes(n):
    prime = []
    data = [i for i in range(2, n + 1)]
    while True:
        p = data[0]
        if n <= p**2:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return data


def factorize(N):  # 素因数分解
    prime = set()
    for p in prime_list:
        if p * p > N:
            break
        while N % p == 0:
            N //= p
            prime.add(p)
    if N > 1:
        prime.add(N)
    return prime


n = int(input())
a = list(map(int, input().split()))

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print("not coprime")
    exit()

prime_list = eratosthenes(10**6)
num = set()
for ai in a:
    prime = factorize(ai)
    if len(prime & num) > 0:
        print("setwise coprime")
        break
    num |= prime
else:
    print("pairwise coprime")
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
import math
from functools import reduce

n = int(input())
a_list = list(map(int, input().split()))
max = a_list[-1] + 1
memo = [0] * max

for a in a_list:
    memo[a] += 1

for i in range(2, max):
    if sum(memo[i::i]) > 1:
        if reduce(math.gcd, a_list) == 1:
            print("setwise coprime")
            exit()
        else:
            print("not coprime")
            exit()

print("pairwise coprime")


Fixed submission:
import math
from functools import reduce

n = int(input())
a_list = list(map(int, input().split()))
max = 10**6 + 1
memo = [0] * max

for a in a_list:
    memo[a] += 1

for i in range(2, max):
    if sum(memo[i::i]) > 1:
        if reduce(math.gcd, a_list) == 1:
            print("setwise coprime")
            exit()
        else:
            print("not coprime")
            exit()

print("pairwise coprime")
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
import math
from functools import reduce

n = int(input())
a_list = list(map(int, input().split()))
max = a_list[n - 1] + 100
memo = [0] * max

for a in a_list:
    memo[a] += 1

for i in range(2, max):
    if sum(memo[i::i]) > 1:
        if reduce(math.gcd, a_list) == 1:
            print("setwise coprime")
            exit()
        else:
            print("not coprime")
            exit()

print("pairwise coprime")


Fixed submission:
import math
from functools import reduce

n = int(input())
a_list = list(map(int, input().split()))
max = 10**6 + 1
memo = [0] * max

for a in a_list:
    memo[a] += 1

for i in range(2, max):
    if sum(memo[i::i]) > 1:
        if reduce(math.gcd, a_list) == 1:
            print("setwise coprime")
            exit()
        else:
            print("not coprime")
            exit()

print("pairwise coprime")
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define io                                                                     \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 200005;
const int mod = 1e9 + 7;
int main() {
  io;
  int n, a[N];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int x = a[0];
  for (int i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (mp[j]) {
          cout << "setwise coprime";
          return 0;
        }
        mp[j]++;
        while (a[i] % j == 0)
          a[i] /= j;
      }
    }
    if (a[i] != 1) {
      if (mp[a[i]]) {
        cout << "setwise coprime";
        return 0;
      }
      mp[a[i]]++;
    }
  }
  cout << "pairwise coprime";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define io                                                                     \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 1000005;
const int mod = 1e9 + 7;
int main() {
  io;
  int n, a[N];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int x = a[0];
  for (int i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (mp[j]) {
          cout << "setwise coprime";
          return 0;
        }
        mp[j]++;
        while (a[i] % j == 0)
          a[i] /= j;
      }
    }
    if (a[i] != 1) {
      if (mp[a[i]]) {
        cout << "setwise coprime";
        return 0;
      }
      mp[a[i]]++;
    }
  }
  cout << "pairwise coprime";
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair<ll, ll>
#define nl "\n"
const int L = 1000006;
ll spf[L + 10];
map<ll, ll> x;
ll soe() {
  ll i, j;
  for (i = 1; i <= L; i++)
    spf[i] = i;
  for (i = 2; i * i <= L; i++) {
    if (spf[i] == i) {
      for (j = i * i; j <= L; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}
vector<ll> factorise(ll x) {
  vector<ll> v;
  while (x != 1) {
    v.pb(spf[x]);
    x = x / spf[x];
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  ll n, i;
  soe();
  cin >> n;
  ll a[n + 2];
  for (i = 0; i < n; i++)
    cin >> a[i];
  ll gcd = a[0];
  for (i = 1; i < n; i++)
    gcd = __gcd(gcd, a[i]);
  // for(i=1;i<L;i++)
  // {
  // 	factorise(i);
  // }
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    for (auto y : sub) {
      x[y]++;
    }
  }
  ll ff = 0;
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    map<ll, ll> subb;
    for (auto it : sub)
      subb[it]++;
    ll f = 0;
    for (auto y : subb) {
      ll p = x[y.ff] - y.ss;
      if (p != 0) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      ff = 1;
      break;
    }
  }
  if (ff == 0)
    cout << "pairwise coprime";
  else if (gcd == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  cout << nl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair<ll, ll>
#define nl "\n"
const int L = 1000006;
ll spf[L + 10];
map<ll, ll> x;
void soe() {
  ll i, j;
  for (i = 1; i <= L; i++)
    spf[i] = i;
  for (i = 2; i * i <= L; i++) {
    if (spf[i] == i) {
      for (j = i * i; j <= L; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}
vector<ll> factorise(ll x) {
  vector<ll> v;
  while (x != 1) {
    v.pb(spf[x]);
    x = x / spf[x];
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  ll n, i;
  soe();
  cin >> n;
  ll a[n + 2];
  for (i = 0; i < n; i++)
    cin >> a[i];
  ll gcd = a[0];
  for (i = 1; i < n; i++)
    gcd = __gcd(gcd, a[i]);
  // for(i=1;i<L;i++)
  // {
  // 	factorise(i);
  // }
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    for (auto y : sub) {
      x[y]++;
    }
  }
  ll ff = 0;
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    map<ll, ll> subb;
    for (auto it : sub)
      subb[it]++;
    ll f = 0;
    for (auto y : subb) {
      ll p = x[y.ff] - y.ss;
      if (p != 0) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      ff = 1;
      break;
    }
  }
  if (ff == 0)
    cout << "pairwise coprime";
  else if (gcd == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  cout << nl;
  return 0;
}
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))

# 解説AC(a*loga)
ans = 0
cnt = [0] * (max(a) + 1)
for ai in a:
    ans = gcd(ans, ai)
    cnt[ai] += 1

if ans != 1:
    print("not coprime")
elif any(sum(cnt[i::i]) > 1 for i in range(max(a) + 1)):
    print("setwise coprime")
else:
    print("pairwise coprime")


Fixed submission:
from math import gcd

n = int(input())
a = list(map(int, input().split()))

# 解説AC(a*loga)
ans = 0
cnt = [0] * (max(a) + 1)
for ai in a:
    ans = gcd(ans, ai)
    cnt[ai] += 1

if ans != 1:
    print("not coprime")
elif any(sum(cnt[i::i]) > 1 for i in range(2, max(a) + 1)):
    print("setwise coprime")
else:
    print("pairwise coprime")
Problem p02575 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid (l + r) / 2
#define rep(i, l, r) for (int i = l; i <= r; ++i)
typedef long long ll;
const int N = 800000 + 5;
struct tree {
  int min, tag;
} t[N];
int n, m, a, b, fir;
int read() {
  char c;
  int x = 0, f = 1;
  c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
void lazy(int p, int k) { t[p].min = t[p].tag = k; }
void down(int p, int l, int r) {
  if (!t[p].tag)
    return;
  lazy(ls, t[p].tag), lazy(rs, t[p].tag + mid - l + 1);
  t[p].tag = 0;
}
void update(int p, int l, int r, int x, int y, int k) {
  down(p, l, r);
  if (l >= x && r <= y) {
    lazy(p, k);
    return;
  }
  if (mid >= x)
    update(ls, l, mid, x, y, k);
  if (mid < y)
    update(rs, mid + 1, r, x, y, k + max(0, mid - max(l, x) + 1));
  t[p].min = min(t[ls].min, t[rs].min);
}
int query(int p, int l, int r, int x, int y) {
  if (l >= x && r <= y)
    return t[p].min;
  down(p, l, r);
  if (mid >= x)
    return query(ls, l, mid, x, y);
  else
    return query(rs, mid + 1, r, x, y);
}
int main() {
  n = read(), m = read();
  rep(i, 1, n) {
    a = read(), b = read();
    fir = (a == 1 ? m + 1 : query(1, 1, m, a - 1, a - 1) + 1);
    update(1, 1, m, a, b, fir);
    printf("%d\n", t[1].min >= m + 1 ? -1 : t[1].min + i);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid (l + r) / 2
#define rep(i, l, r) for (int i = l; i <= r; ++i)
typedef long long ll;
const int N = 80000000 + 5;
struct tree {
  int min, tag;
} t[N];
int n, m, a, b, fir;
int read() {
  char c;
  int x = 0, f = 1;
  c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
void lazy(int p, int k) { t[p].min = t[p].tag = k; }
void down(int p, int l, int r) {
  if (!t[p].tag)
    return;
  lazy(ls, t[p].tag), lazy(rs, t[p].tag + mid - l + 1);
  t[p].tag = 0;
}
void update(int p, int l, int r, int x, int y, int k) {
  down(p, l, r);
  if (l >= x && r <= y) {
    lazy(p, k);
    return;
  }
  if (mid >= x)
    update(ls, l, mid, x, y, k);
  if (mid < y)
    update(rs, mid + 1, r, x, y, k + max(0, mid - max(l, x) + 1));
  t[p].min = min(t[ls].min, t[rs].min);
}
int query(int p, int l, int r, int x, int y) {
  if (l >= x && r <= y)
    return t[p].min;
  down(p, l, r);
  if (mid >= x)
    return query(ls, l, mid, x, y);
  else
    return query(rs, mid + 1, r, x, y);
}
int main() {
  n = read(), m = read();
  rep(i, 1, n) {
    a = read(), b = read();
    fir = (a == 1 ? m + 1 : query(1, 1, m, a - 1, a - 1) + 1);
    update(1, 1, m, a, b, fir);
    printf("%d\n", t[1].min >= m + 1 ? -1 : t[1].min + i);
  }
  return 0;
}