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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
ll dep(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return dep(b, a % b);
}
int main() {
  ll n;
  cin >> n;
  ll ch[1000010];
  for (ll i = 0; i < n; i++) {
    cin >> ch[i];
  }
  ll ch2[1000010] = {};
  for (ll i = 2; i < 1000010; i++) {
    if (ch2[i] != 0) {
      continue;
    }
    for (ll j = 1; i * j < 100010; j++) {
      ll now = i * j;
      if (ch2[now] == 0) {
        ch2[i * j] = i;
      }
    }
  }
  // for(ll i=0;i<1000010;i++){
  // cout << i<< " "<<ch2[i]<<endl;
  //}
  ll ch3[1000010] = {};
  bool ans1 = true;
  // cout <<ans1<<endl;
  for (ll i = 0; i < n; i++) {
    ll now = ch[i];
    while (now != 1) {
      ll next = ch2[now];
      if (ch3[next] == 1) {
        ans1 = false;
        break;
      }
      ch3[next] = 1;
      while (now % next == 0) {
        now /= next;
      }
    }
    if (ans1 == false) {
      break;
    }
  }
  if (ans1) {
    cout << "pairwise coprime";
    return 0;
  }
  ll gcd = ch[0];
  for (ll i = 1; i < n; i++) {
    gcd = dep(max(gcd, ch[i]), min(gcd, ch[i]));
  }
  if (gcd == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
ll dep(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return dep(b, a % b);
}
int main() {
  ll n;
  cin >> n;
  ll ch[1000010];
  for (ll i = 0; i < n; i++) {
    cin >> ch[i];
  }
  ll ch2[1000010] = {};
  for (ll i = 2; i < 1000010; i++) {
    if (ch2[i] != 0) {
      continue;
    }
    for (ll j = 1; i * j < 1000010; j++) {
      ll now = i * j;
      if (ch2[now] == 0) {
        ch2[i * j] = i;
      }
    }
  }
  // for(ll i=0;i<1000010;i++){
  // cout << i<< " "<<ch2[i]<<endl;
  //}
  ll ch3[1000010] = {};
  bool ans1 = true;
  // cout <<ans1<<endl;
  for (ll i = 0; i < n; i++) {
    ll now = ch[i];
    while (now != 1) {
      ll next = ch2[now];
      if (ch3[next] == 1) {
        ans1 = false;
        break;
      }
      ch3[next] = 1;
      while (now % next == 0) {
        now /= next;
      }
    }
    if (ans1 == false) {
      break;
    }
  }
  if (ans1) {
    cout << "pairwise coprime";
    return 0;
  }
  ll gcd = ch[0];
  for (ll i = 1; i < n; i++) {
    gcd = dep(max(gcd, ch[i]), min(gcd, ch[i]));
  }
  if (gcd == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  // your code goes here
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

void st() { cout << "setwise coprime"; }

void pr() { cout << "pairwise coprime"; }

void no() { cout << "not coprime"; }
bool primechk[1000007];
map<long long, long long> mp;

int main() {
  long long n, i, x, cnt, j, bb = 0;
  // preprocess(1000004);
  cin >> n;
  long long arr[n + 5];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (i = 0; i < n; i++) {
    x = arr[i];
    for (j = 2; j * j <= x; j++) {
      if (x % j == 0) {
        mp[j]++;
        if (mp[j] == n) {
          no();
          return 0;
        } else if (mp[j] > 1) {
          bb = 1;
        }
        while (x % j == 0) {
          x /= j;
        }
      }
    }
    if (x >= 2) {
      mp[x]++;
      if (mp[x] == n) {
        no();
        return 0;
      } else if (mp[x] > 1) {
        bb = 1;
      }
    }
  }
  if (bb) {
    st();
  } else {
    pr();
  }
  return 0;
}

Fixed submission:
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

void st() { cout << "setwise coprime"; }

void pr() { cout << "pairwise coprime"; }

void no() { cout << "not coprime"; }
bool primechk[1000007];
map<long long, long long> mp;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, x, cnt, j, bb = 0;
  // preprocess(1000004);
  cin >> n;
  long long arr[n + 5];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (i = 0; i < n; i++) {
    x = arr[i];
    for (j = 2; j * j <= x; j++) {
      if (x % j == 0) {
        mp[j]++;
        if (mp[j] == n) {
          no();
          return 0;
        } else if (mp[j] > 1) {
          bb = 1;
        }
        while (x % j == 0) {
          x /= j;
        }
      }
    }
    if (x >= 2) {
      mp[x]++;
      if (mp[x] == n) {
        no();
        return 0;
      } else if (mp[x] > 1) {
        bb = 1;
      }
    }
  }
  if (bb) {
    st();
  } else {
    pr();
  }
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define MAXN 100001
using namespace std;
ll spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;
  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}
void get(map<ll, ll> &ma, ll a[], ll n) {
  //	ll f=0;
  for (ll i = 0; i < n; i++) {
    while (a[i] != 1) {
      ma[spf[a[i]]]++;
      ll temp = spf[a[i]];
      // cout<<temp<<endl;
      while (spf[a[i]] == temp) {
        a[i] = a[i] / spf[a[i]];
      }
    }
  }
  ll gcd = 1, f = 0;
  map<ll, ll>::iterator it;
  for (it = ma.begin(); it != ma.end(); it++) {
    ll d = (it->second) / n;
    //	cout<<it->first<<" "<<it->second<<" "<<d<<endl;
    if (d != 0)
      gcd = gcd * (it->first);
    if (it->second != 1) {
      f = 1;
    }
  }
  if (f == 0) {
    cout << "pairwise coprime" << endl;
  } else if (gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
int main() {
  sieve();
  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> ma;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  get(ma, a, n);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define MAXN 1000001
using namespace std;
ll spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;
  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}
void get(map<ll, ll> &ma, ll a[], ll n) {
  //	ll f=0;
  for (ll i = 0; i < n; i++) {
    while (a[i] != 1) {
      ma[spf[a[i]]]++;
      ll temp = spf[a[i]];
      // cout<<temp<<endl;
      while (spf[a[i]] == temp) {
        a[i] = a[i] / spf[a[i]];
      }
    }
  }
  ll gcd = 1, f = 0;
  map<ll, ll>::iterator it;
  for (it = ma.begin(); it != ma.end(); it++) {
    ll d = (it->second) / n;
    //	cout<<it->first<<" "<<it->second<<" "<<d<<endl;
    if (d != 0)
      gcd = gcd * (it->first);
    if (it->second != 1) {
      f = 1;
    }
  }
  if (f == 0) {
    cout << "pairwise coprime" << endl;
  } else if (gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
int main() {
  sieve();
  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> ma;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  get(ma, a, n);
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll N;
ll A[1000010];
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; i++)
    cin >> A[i];
  sort(A, A + N);
  bool pairwise = true;
  bool isPrime[1000010];
  for (ll i = 1; i <= A[N - 1]; i++)
    isPrime[i] = true;
  for (ll i = 0; i < N; i++) {
    if (!isPrime[A[i]]) {
      pairwise = false;
      break;
    }
    vector<ll> v;
    ll a = A[i];
    for (ll j = 2; j <= a; j++) {
      if (a % j == 0)
        v.push_back(j);
      while (a % j == 0)
        a /= j;
    }
    if (a != 1)
      v.push_back(a);
    for (auto x : v) {
      for (ll j = x; j <= A[N - 1]; j += x) {
        isPrime[j] = false;
      }
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll _gcd = A[0];
  for (ll i = 1; i < N; i++) {
    _gcd = gcd(_gcd, A[i]);
  }
  if (_gcd == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll N;
ll A[1000010];
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; i++)
    cin >> A[i];
  sort(A, A + N);
  bool pairwise = true;
  bool isPrime[1000010];
  for (ll i = 1; i <= A[N - 1]; i++)
    isPrime[i] = true;
  for (ll i = 0; i < N; i++) {
    if (!isPrime[A[i]]) {
      pairwise = false;
      break;
    }
    vector<ll> v;
    ll a = A[i];
    for (ll j = 2; j * j <= a; j++) {
      if (a % j == 0)
        v.push_back(j);
      while (a % j == 0)
        a /= j;
    }
    if (a != 1)
      v.push_back(a);
    for (auto x : v) {
      for (ll j = x; j <= A[N - 1]; j += x) {
        isPrime[j] = false;
      }
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll _gcd = A[0];
  for (ll i = 1; i < N; i++) {
    _gcd = gcd(_gcd, A[i]);
  }
  if (_gcd == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, N) for (ll i = 0; i < N; i++)
using ll = long long;
using namespace std;
#define MOD 1000000007
typedef pair<ll, ll> Pl;
typedef vector<int> vi;

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  int ggg = a[0];
  rep(i, n - 1) ggg = __gcd(ggg, a[i + 1]);
  int cnt = 0, flag = 1;
  rep(i, n) {
    if (a[i] % 2 == 0) {
      while (a[i] % 2 == 0)
        a[i] /= 2;
      cnt++;
    }
  }
  if (cnt > 1) {
    flag = 0;
  }
  if (flag) {
    for (int j = 3; j < 1000; j += 2) {
      cnt = 0;
      rep(i, n) {
        if (a[i] % j == 0) {
          if (a[i] % j == 0) {
            while (a[i] % j == 0)
              a[i] /= j;
            cnt++;
          }
        }
      }
      if (cnt > 1) {
        flag = 0;
        break;
      }
    }
  }
  if (flag) {
    int ch[101010] = {0};
    rep(i, n) {
      if (a[i] != 1) {
        if (ch[a[i]]) {
          flag = 0;
          break;
        } else {
          ch[a[i]]++;
        }
      }
    }
  }

  if (flag) {
    puts("pairwise coprime");
  } else if (ggg == 1) {
    puts("setwise coprime");
  } else {
    puts("not coprime");
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, N) for (ll i = 0; i < N; i++)
using ll = long long;
using namespace std;
#define MOD 1000000007
typedef pair<ll, ll> Pl;
typedef vector<int> vi;

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  int ggg = a[0];
  rep(i, n - 1) ggg = __gcd(ggg, a[i + 1]);
  int cnt = 0, flag = 1;
  rep(i, n) {
    if (a[i] % 2 == 0) {
      while (a[i] % 2 == 0)
        a[i] /= 2;
      cnt++;
    }
  }
  if (cnt > 1) {
    flag = 0;
  }
  if (flag) {
    for (int j = 3; j < 1000; j += 2) {
      cnt = 0;
      rep(i, n) {
        if (a[i] % j == 0) {
          if (a[i] % j == 0) {
            while (a[i] % j == 0)
              a[i] /= j;
            cnt++;
          }
        }
      }
      if (cnt > 1) {
        flag = 0;
        break;
      }
    }
  }
  if (flag) {
    int ch[1010101] = {0};
    rep(i, n) {
      if (a[i] != 1) {
        if (ch[a[i]]) {
          flag = 0;
          break;
        } else {
          ch[a[i]]++;
        }
      }
    }
  }

  if (flag) {
    puts("pairwise coprime");
  } else if (ggg == 1) {
    puts("setwise coprime");
  } else {
    puts("not coprime");
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n];
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  int dp[100003]{};

  bool z = false;
  rep(i, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        if (dp[j] != 0) {
          z = true;
          break;
        } else {
          dp[j] = 1;
          while (q % j == 0)
            q /= j;
        }
      }
    }
    if (q != 1 && dp[q] == 1) {
      z = true;
      break;
    } else if (q != 1) {
      dp[q] = 1;
    }
    if (z)
      break;
  }
  // rep(i,n){
  //     if(a[i]==a[i+1]){
  //         z=true;
  //         break;
  //     }

  //     for(int j=1;a[i]*j<=a[n-1];j++){
  //         if(j==1&&dp[a[i]*j]!=0){
  //             z=true;
  //             break;
  //             //z=true;
  //         }else dp[a[i]*j]=1;
  //     }
  //     if(z)break;
  // }
  // //cout<<z << " ";
  // rep(i,20)cout<<dp[i]<<" ";
  if (z == false) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int p = a[0];
  for (int i = 1; i < n; i++) {
    p = __gcd(p, a[i]);
  }
  if (p == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n];
  rep(i, n) { cin >> a[i]; }
  // sort(a,a+n);
  int dp[1000003]{};

  bool z = false;
  rep(i, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        if (dp[j] != 0) {
          z = true;
          break;
        } else {
          dp[j] = 1;
          while (q % j == 0)
            q /= j;
        }
      }
    }
    if (q != 1 && dp[q] == 1) {
      z = true;
      break;
    } else if (q != 1) {
      dp[q] = 1;
    }
    if (z)
      break;
  }
  // rep(i,n){
  //     if(a[i]==a[i+1]){
  //         z=true;
  //         break;
  //     }

  //     for(int j=1;a[i]*j<=a[n-1];j++){
  //         if(j==1&&dp[a[i]*j]!=0){
  //             z=true;
  //             break;
  //             //z=true;
  //         }else dp[a[i]*j]=1;
  //     }
  //     if(z)break;
  // }
  // //cout<<z << " ";
  // rep(i,20)cout<<dp[i]<<" ";
  if (z == false) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int p = a[0];
  for (int i = 1; i < n; i++) {
    p = __gcd(p, a[i]);
  }
  if (p == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
(*A,) = map(int, input().split())
m = max(A)
C = [0 for a in range(m + 1)]
for a in A:
    C[a] += 1
s = max(sum(C[a::a]) for a in range(2, m + 1))
if s < 2:
    print("pairwise coprime")
elif s < n:
    print("setwise coprime")
else:
    print("not coprime")


Fixed submission:
n = int(input())
(*A,) = map(int, input().split())
m = max(A)
C = [0 for a in range(m + 1)]
for a in A:
    C[a] += 1
s = 0
for a in range(2, m + 1):
    s = max(s, sum(C[a::a]))
if s < 2:
    print("pairwise coprime")
elif s < n:
    print("setwise coprime")
else:
    print("not coprime")
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
(*A,) = map(int, input().split())

m = max(A)
is_prime = [True] * (m + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, m + 1):
    for j in range(i * 2, m + 1, i):
        is_prime[j] = False
primes = [i for i in range(m + 1) if is_prime[i]]

Amap = {a: 0 for a in range(1, m + 1)}
for a in A:
    Amap[a] += 1

# Pmap[p]はAにでてくるpの倍数の数
Pmap = {p: 0 for p in primes}
for p in primes:
    for a in range(p, m + 1, p):
        Pmap[p] += Amap[a]

score = max(Pmap.values())

if score == 1:
    print("pairwise coprime")
elif score != n:
    print("setwise coprime")
else:
    print("not coprime")


Fixed submission:
n = int(input())
(*A,) = map(int, input().split())

m = max(A)
is_prime = [True] * (m + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, m + 1):
    for j in range(i * 2, m + 1, i):
        is_prime[j] = False
primes = [i for i in range(m + 1) if is_prime[i]]

Amap = {a: 0 for a in range(1, m + 1)}
for a in A:
    Amap[a] += 1

# Pmap[p]はAにでてくるpの倍数の数
Pmap = {p: 0 for p in primes}
for p in primes:
    for a in range(p, m + 1, p):
        Pmap[p] += Amap[a]

try:
    score = max(Pmap.values())
except BaseException:
    print("pairwise coprime")
    exit()
if score == 1:
    print("pairwise coprime")
elif score != n:
    print("setwise coprime")
else:
    print("not coprime")
Problem p02574 (C++)

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

#define int long long
#define forn(i, a, n) for (int i = a; i < n; i++)

int n;
int a[1000001];
vector<int> v;
map<int, int> mp;
int isp[1000001];

void buildprime() {
  isp[0] = isp[1] = 1;
  forn(i, 2, 1000001) {
    if (isp[i])
      continue;
    for (int j = i + i; j < 1000001; j += i)
      isp[j] = 1;
  }
  forn(i, 2, 1000001) if (!isp[i]) v.push_back(i);
}

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

bool ispairwise() {
  vector<int> w;
  forn(i, 0, n) {
    int x = a[i];
    forn(i, 0, v.size()) {
      if (v[i] * v[i] > x)
        break;
      if (x % v[i] == 0) {
        mp[v[i]]++;
        w.push_back(v[i]);
        while (x % v[i] == 0) {
          x /= v[i];
        }
      }
    }
    if (x != 1) {
      mp[x]++;
      w.push_back(x);
    }
  }
  sort(w.begin(), w.end());
  int mx = w[w.size() - 1];
  forn(i, 0, v.size()) {
    if (v[i] > mx)
      break;
    if (mp[v[i]] > 1)
      return false;
  }
  return true;
}

bool issetwise() {
  int res = a[0];
  forn(i, 0, n) { res = gcd(res, a[i]); }
  return res == 1;
}

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

  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  buildprime();
  cin >> n;
  forn(i, 0, n) cin >> a[i];
  bool isp = ispairwise();
  bool iss = issetwise();
  if (isp) {
    cout << "pairwise coprime" << endl;
    return 0;
  } else if (iss) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}

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

#define int long long
#define forn(i, a, n) for (int i = a; i < n; i++)

int n;
int a[1000001];
vector<int> v;
map<int, int> mp;
int isp[1000001];

void buildprime() {
  isp[0] = isp[1] = 1;
  forn(i, 2, 1000001) {
    if (isp[i])
      continue;
    for (int j = i + i; j < 1000001; j += i)
      isp[j] = 1;
  }
  forn(i, 2, 1000001) if (!isp[i]) v.push_back(i);
}

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

bool ispairwise() {
  vector<int> w;
  forn(i, 0, n) {
    int x = a[i];
    forn(i, 0, v.size()) {
      if (v[i] * v[i] > x)
        break;
      if (x % v[i] == 0) {
        mp[v[i]]++;
        w.push_back(v[i]);
        while (x % v[i] == 0) {
          x /= v[i];
        }
      }
    }
    if (x != 1 || x == i) {
      mp[x]++;
      w.push_back(x);
    }
  }
  sort(w.begin(), w.end());
  int mx = w[w.size() - 1];
  forn(i, 0, v.size()) {
    if (v[i] > mx)
      break;
    if (mp[v[i]] > 1)
      return false;
  }
  return true;
}

bool issetwise() {
  int res = a[0];
  forn(i, 0, n) { res = gcd(res, a[i]); }
  return res == 1;
}

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

  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  buildprime();
  cin >> n;
  forn(i, 0, n) cin >> a[i];
  bool isp = ispairwise();
  bool iss = issetwise();
  if (isp) {
    cout << "pairwise coprime" << endl;
    return 0;
  } else if (iss) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 2e5 + 100;
typedef long long ll;

// prime次数
int num[N], n;
inline void divide(int x) {
  for (int i = 2; i <= x / i; i++) {
    if (x % i == 0) {
      num[i]++;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    num[x]++;
}
int main() {

  cin >> n;

  int MaxNum = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    divide(x);

    MaxNum = max(MaxNum, x);
  }

  int f1 = 0;
  for (int i = 2; i <= MaxNum; i++) {
    if (num[i] >= n) {
      puts("not coprime");
      return 0;
    }
    if (num[i] > 1) {
      f1 = 1;
      // return 0;
    }
  }
  if (f1)
    puts("setwise coprime");
  else
    puts("pairwise coprime");
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e6 + 100;
typedef long long ll;

// prime次数
int num[N], n;
inline void divide(int x) {
  for (int i = 2; i <= x / i; i++) {
    if (x % i == 0) {
      num[i]++;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    num[x]++;
}
int main() {

  cin >> n;

  int MaxNum = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    divide(x);

    MaxNum = max(MaxNum, x);
  }

  int f1 = 0;
  for (int i = 2; i <= MaxNum; i++) {
    if (num[i] >= n) {
      puts("not coprime");
      return 0;
    }
    if (num[i] > 1) {
      f1 = 1;
      // return 0;
    }
  }
  if (f1)
    puts("setwise coprime");
  else
    puts("pairwise coprime");
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
vector<int> vis(100001, 0);

int flag;

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

int findGCD(vector<int> arr, int n) {
  int result = arr[0];
  for (int i = 1; i < n; i++) {
    result = gcd(arr[i], result);

    if (result == 1) {
      return 1;
    }
  }
  return result;
}

void primeFactors(int n) {
  if (n % 2 == 0) {
    if (vis[2] == 0) {
      vis[2] = 1;

    } else {
      flag = 1;
      return;
    }
  }
  while (n % 2 == 0) {
    n = n / 2;
  }

  for (int i = 3; i <= sqrt(n); i = i + 2) {
    if (n % i == 0) {
      if (vis[i] == 0) {
        vis[i] = 1;
      } else {
        flag = 1;
        return;
      }
    }

    while (n % i == 0) {
      n = n / i;
    }
  }

  if (n > 2) {
    if (vis[n] == 0) {
      vis[n] = 1;
    } else {
      flag = 1;
      return;
    }
  }
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    if (flag == 1) {
      break;
    }
    primeFactors(v[i]);
  }
  if (flag == 0) {
    cout << "pairwise coprime";
    return;
  }
  if (findGCD(v, v.size()) == 1) {
    cout << "setwise coprime";
    return;
  }
  cout << "not coprime";
  return;
}

int main() {

  int t;
  // cin>>t;
  t = 1;
  while (t--) {

    solve();
    cout << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
vector<int> vis(1000001, 0);

int flag;

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

int findGCD(vector<int> arr, int n) {
  int result = arr[0];
  for (int i = 1; i < n; i++) {
    result = gcd(arr[i], result);

    if (result == 1) {
      return 1;
    }
  }
  return result;
}

void primeFactors(int n) {
  if (n % 2 == 0) {
    if (vis[2] == 0) {
      vis[2] = 1;

    } else {
      flag = 1;
      return;
    }
  }
  while (n % 2 == 0) {
    n = n / 2;
  }

  for (int i = 3; i <= sqrt(n); i = i + 2) {
    if (n % i == 0) {
      if (vis[i] == 0) {
        vis[i] = 1;
      } else {
        flag = 1;
        return;
      }
    }

    while (n % i == 0) {
      n = n / i;
    }
  }

  if (n > 2) {
    if (vis[n] == 0) {
      vis[n] = 1;
    } else {
      flag = 1;
      return;
    }
  }
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    if (flag == 1) {
      break;
    }
    primeFactors(v[i]);
  }
  if (flag == 0) {
    cout << "pairwise coprime";
    return;
  }
  if (findGCD(v, v.size()) == 1) {
    cout << "setwise coprime";
    return;
  }
  cout << "not coprime";
  return;
}

int main() {

  int t;
  // cin>>t;
  t = 1;
  while (t--) {

    solve();
    cout << endl;
  }
}
Problem p02574 (C++)

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

using namespace std;
using ll = long long;
int a[1000005];
unordered_map<int, int> mp;
int num[1000005];
int main() {
#ifdef LOCAL
  freopen("in1.txt", "r", stdin);
  freopen("out1.txt", "w", stdout);
#endif

  int n;
  cin >> n;

  // bool cjs = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    // if(a[i] == 1) cjs = true;
    mp[a[i]] = 1;
    num[a[i]]++;
  }
  //    if(cjs) {
  //        puts("not coprime");
  //        exit(0);
  //    }
  bool dyh = false;
  for (int i = 2; i < 1000005; i++) {
    bool flag = false;
    for (int j = 1; i * j < 1000010; j++) {
      if (mp[i * j] == 1 and num[i * j] > 1) {
        dyh = true;
        break;
      }
      if (mp[i * j] == 1 and flag) {
        dyh = true;
        break;
      }
      if (mp[i * j] == 1 and !flag)
        flag = true;
    }
  }
  if (dyh) {
    int tmp = a[0];
    for (int i = 1; i < n; i++) {
      tmp = __gcd(tmp, a[i]);
    }
    if (tmp == 1) {
      puts("setwise coprime");
    } else
      puts("not coprime");
  } else {
    puts("pairwise coprime");
  }
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int a[1000005];
unordered_map<int, int> mp;
int num[1000010];
int main() {
#ifdef LOCAL
  freopen("in1.txt", "r", stdin);
  freopen("out1.txt", "w", stdout);
#endif

  int n;
  cin >> n;

  // bool cjs = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    // if(a[i] == 1) cjs = true;
    mp[a[i]] = 1;
    num[a[i]]++;
  }
  //    if(cjs) {
  //        puts("not coprime");
  //        exit(0);
  //    }
  bool dyh = false;
  for (int i = 2; i < 1000005; i++) {
    bool flag = false;
    for (int j = 1; i * j < 1000010; j++) {
      if (mp[i * j] == 1 and num[i * j] > 1) {
        dyh = true;
        break;
      }
      if (mp[i * j] == 1 and flag) {
        dyh = true;
        break;
      }
      if (mp[i * j] == 1 and !flag)
        flag = true;
    }
  }
  if (dyh) {
    int tmp = a[0];
    for (int i = 1; i < n; i++) {
      tmp = __gcd(tmp, a[i]);
    }
    if (tmp == 1) {
      puts("setwise coprime");
    } else
      puts("not coprime");
  } else {
    puts("pairwise coprime");
  }
  return 0;
}
Problem p02574 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) scanf("%d", a[i]);
  vector<int> cnt(1000005);
  vector<int> m(1000005);
  rep(i, n) m[a[i]]++;
  bool flag = true;
  for (int i = 2; i <= 1000000; i++) {
    int t = 0;
    if (cnt[i] != 0)
      continue;
    for (int j = i; j <= 1000000; j += i) {
      t += m[j];
      cnt[j]++;
    }
    if (t >= 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  rep(i, n) g = __gcd(g, a[i]);
  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) scanf("%d", &a[i]);
  vector<int> cnt(1000005);
  vector<int> m(1000005);
  rep(i, n) m[a[i]]++;
  bool flag = true;
  for (int i = 2; i <= 1000000; i++) {
    int t = 0;
    if (cnt[i] != 0)
      continue;
    for (int j = i; j <= 1000000; j += i) {
      t += m[j];
      cnt[j]++;
    }
    if (t >= 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  rep(i, n) g = __gcd(g, a[i]);
  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define MOD 1000000007
vector<int> prime;
bool is[1000001];
int cnt[1000001];
void gen() {
  for (int i = 0; i <= 1000000; i++)
    is[i] = true;
  is[0] = is[1] = false;
  for (int i = 2; i <= 1000000; i++) {
    for (int j = i + i; j <= 1000000; j += i) {
      is[j] = false;
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    if (is[i] == true)
      prime.push_back(i);
  }
}
int main() {
  gen();
  int a;
  cin >> a;
  int arr[a];
  for (int i = 0; i < a; i++)
    cin >> arr[i];
  for (int i = 0; i < a; i++) {
    int cur = arr[i];
    for (int i = 0; i < prime.size(); i++) {
      if (cur % prime[i] == 0) {
        cur /= prime[i];
        cnt[prime[i]]++;
      }
      while (cur % prime[i] == 0)
        cur /= prime[i];
      if (cur == 1) {
        break;
      }
    }
  }
  int key1 = 0, key2 = 0;
  for (int i = 1; i <= 1000000; i++) {
    if (cnt[i] >= 2)
      key1 = 1;
    if (cnt[i] == a)
      key2 = 1;
  }
  if (key1 == 0)
    cout << "pairwise coprime\n";
  else if (key2 == 0)
    cout << "setwise coprime\n";
  else
    cout << "not coprime\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define MOD 1000000007
vector<int> prime;
bool is[1000001];
int cnt[1000001];
void gen() {
  for (int i = 0; i <= 1000000; i++)
    is[i] = true;
  is[0] = is[1] = false;
  for (int i = 2; i <= 1000000; i++) {
    for (int j = i + i; j <= 1000000; j += i) {
      is[j] = false;
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    if (is[i] == true)
      prime.push_back(i);
  }
}
int main() {
  gen();
  int a;
  cin >> a;
  int arr[a];
  for (int i = 0; i < a; i++)
    cin >> arr[i];
  for (int i = 0; i < a; i++) {
    int cur = arr[i];
    for (int i = 0; i < prime.size(); i++) {
      if (cur % prime[i] == 0) {
        cur /= prime[i];
        cnt[prime[i]]++;
      }
      while (cur % prime[i] == 0)
        cur /= prime[i];
      if (is[cur] == true) {
        cnt[cur]++;
        break;
      }
      if (cur == 1) {
        break;
      }
    }
  }
  int key1 = 0, key2 = 0;
  for (int i = 1; i <= 1000000; i++) {
    if (cnt[i] >= 2)
      key1 = 1;
    if (cnt[i] == a)
      key2 = 1;
  }
  if (key1 == 0)
    cout << "pairwise coprime\n";
  else if (key2 == 0)
    cout << "setwise coprime\n";
  else
    cout << "not coprime\n";
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

signed main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, 0, n) cin >> a[i];
  bool p = 1, s = 1;

  set<int> st;
  rep(i, 0, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        // if (*st.find(j) == j) {
        if (st.count(j) > 0) {
          p = 0;
          break;
        }
        st.insert(j);
        while (q % j == 0) {
          q /= j;
        }
      }
    }
    assert(q >= 1);
    if (q != 1) {
      assert((*st.find(q) == q) == (st.count(q) > 0));
      // if (*st.find(q) == q) p = 0;
      // if(st.count(q)>0)p=0;
      if (st.find(q) != st.end())
        p = 0;
    }
    st.insert(q);
    if (!p)
      break;
  }

  // for (auto p : st) cout << p << " ";

  int now = a[0];
  rep(i, 0, n) { now = gcd(now, a[i]); }
  if (now != 1)
    s = 0;

  if (p) {
    cout << "pairwise coprime\n";
  } else if (s) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
}


Fixed submission:
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

signed main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, 0, n) cin >> a[i];
  bool p = 1, s = 1;

  set<int> st;
  rep(i, 0, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        // if (*st.find(j) == j) {
        if (st.count(j) > 0) {
          p = 0;
          break;
        }
        st.insert(j);
        while (q % j == 0) {
          q /= j;
        }
      }
    }
    assert(q >= 1);
    if (q != 1) {
      // assert((*st.find(q)==q)==(st.count(q)>0));
      // if (*st.find(q) == q) p = 0;
      // if(st.count(q)>0)p=0;
      if (st.find(q) != st.end())
        p = 0;
    }
    st.insert(q);
    if (!p)
      break;
  }

  // for (auto p : st) cout << p << " ";

  int now = a[0];
  rep(i, 0, n) { now = gcd(now, a[i]); }
  if (now != 1)
    s = 0;

  if (p) {
    cout << "pairwise coprime\n";
  } else if (s) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

signed main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, 0, n) cin >> a[i];
  bool p = 1, s = 1;

  set<int> st;
  rep(i, 0, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        assert((*st.find(j) == j) && (st.count(j) > 0));
        // if (*st.find(j) == j) {
        if (st.count(j) > 0) {
          p = 0;
          break;
        }
        st.insert(j);
        while (q % j == 0) {
          q /= j;
        }
      }
    }
    assert(q >= 1);
    if (q != 1) {
      // if (*st.find(q) == q) p = 0;
      if (st.count(q) > 0)
        p = 0;
    }
    st.insert(q);
    if (!p)
      break;
  }

  // for (auto p : st) cout << p << " ";

  int now = a[0];
  rep(i, 0, n) { now = gcd(now, a[i]); }
  if (now != 1)
    s = 0;

  if (p) {
    cout << "pairwise coprime\n";
  } else if (s) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
}


Fixed submission:
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

signed main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, 0, n) cin >> a[i];
  bool p = 1, s = 1;

  set<int> st;
  rep(i, 0, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        assert((*st.find(j) == j) == (st.count(j) > 0));
        // if (*st.find(j) == j) {
        if (st.count(j) > 0) {
          p = 0;
          break;
        }
        st.insert(j);
        while (q % j == 0) {
          q /= j;
        }
      }
    }
    assert(q >= 1);
    if (q != 1) {
      // if (*st.find(q) == q) p = 0;
      if (st.count(q) > 0)
        p = 0;
    }
    st.insert(q);
    if (!p)
      break;
  }

  // for (auto p : st) cout << p << " ";

  int now = a[0];
  rep(i, 0, n) { now = gcd(now, a[i]); }
  if (now != 1)
    s = 0;

  if (p) {
    cout << "pairwise coprime\n";
  } else if (s) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
}
Problem p02574 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int T = 0; T < t; T++) {
    ll n;
    cin >> n;
    ll a[n], cnt[100000001] = {0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      cnt[a[i]]++;
    }
    bool ok = true;
    for (ll i = 2; i <= 1e6; i++) {
      ll ans = 0;
      for (ll j = i; j <= 1e6; j += i) {
        ans += cnt[j];
      }
      if (ans > 1) {
        ok = false;
        break;
      }
    }
    if (ok == true)
      cout << "pairwise coprime" << endl;
    else {
      ll gh = a[0];
      for (int i = 1; i < n; i++)
        gh = __gcd(gh, a[i]);
      if (gh == 1)
        cout << "setwise coprime" << endl;
      else
        cout << "not coprime" << endl;
    }
  }
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int T = 0; T < t; T++) {
    ll n;
    cin >> n;
    ll a[n], cnt[10000001] = {0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      cnt[a[i]]++;
    }
    bool ok = true;
    for (ll i = 2; i <= 1e6; i++) {
      ll ans = 0;
      for (ll j = i; j <= 1e6; j += i) {
        ans += cnt[j];
      }
      if (ans > 1) {
        ok = false;
        break;
      }
    }
    if (ok == true)
      cout << "pairwise coprime" << endl;
    else {
      ll gh = a[0];
      for (int i = 1; i < n; i++)
        gh = __gcd(gh, a[i]);
      if (gh == 1)
        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;

const int maxm = 1e4 + 5;

int a[maxm], mf[maxm];
unordered_map<int, int> ump;
bool not_pairwise = false;

void init() {
  mf[1] = 1;
  for (int i = 2; i < maxm; i += 2) {
    mf[i] = 2;
  }
  for (int i = 3; i < maxm; i += 2) {
    if (!mf[i]) {
      mf[i] = i;
      for (long long j = 1ll * i * i; j < maxm; j += i) {
        mf[j] = i;
      }
    }
  }
}

void factorize(int x) {
  vector<int> a;
  while (x > 1) {
    a.push_back(mf[x]);
    x /= mf[x];
  }
  for (int y : a) {
    if (ump[y] == 1) {
      not_pairwise = true;
    }
  }
  for (int y : a) {
    ump[y] = 1;
  }
}

int main() {
  init();
  int n;
  cin >> n;
  int g = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (g == -1)
      g = a[i];
    else
      g = __gcd(g, a[i]);
    factorize(a[i]);
  }
  if (!not_pairwise)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}

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

using namespace std;

const int maxm = 1e6 + 5;

int a[maxm], mf[maxm];
unordered_map<int, int> ump;
bool not_pairwise = false;

void init() {
  mf[1] = 1;
  for (int i = 2; i < maxm; i += 2) {
    mf[i] = 2;
  }
  for (int i = 3; i < maxm; i += 2) {
    if (!mf[i]) {
      mf[i] = i;
      for (long long j = 1ll * i * i; j < maxm; j += i) {
        mf[j] = i;
      }
    }
  }
}

void factorize(int x) {
  vector<int> a;
  while (x > 1) {
    a.push_back(mf[x]);
    x /= mf[x];
  }
  for (int y : a) {
    if (ump[y] == 1) {
      not_pairwise = true;
    }
  }
  for (int y : a) {
    ump[y] = 1;
  }
}

int main() {
  init();
  int n;
  cin >> n;
  int g = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (g == -1)
      g = a[i];
    else
      g = __gcd(g, a[i]);
    factorize(a[i]);
  }
  if (!not_pairwise)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}
Problem p02574 (Python)

Buggy submission (status: Runtime Error):
import collections

N = int(input())
A = [int(_) for _ in input().split()]


def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a


d = collections.defaultdict(int)
for a in A:
    for x in prime_factorize(a):
        d[x] += 1
e = max(d.values())
if e == 1:
    ans = "pairwise coprime"
elif e == N:
    ans = "not coprime"
else:
    ans = "setwise coprime"
print(ans)


Fixed submission:
import collections

N = int(input())
A = [int(_) for _ in input().split()]


def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a


d = collections.defaultdict(int)
for a in A:
    for x in prime_factorize(a):
        d[x] += 1
if len(d):
    e = max(d.values())
if len(d) == 0 or e == 1:
    ans = "pairwise coprime"
elif e == N:
    ans = "not coprime"
else:
    ans = "setwise coprime"
print(ans)
Problem p02574 (C++)

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

vector<int> Eratosthenes(const int N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  vector<int> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

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

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

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

  vector<int> prime = Eratosthenes(ma);

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

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

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

vector<int> Eratosthenes(const int N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  vector<int> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

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

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

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

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

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

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

Buggy submission (status: Runtime Error):
N = int(input())
A = [int(s) for s in input().split()]

PRIME_LENGTH = 10**6

prime_list = [[] for _ in range(PRIME_LENGTH)]

for i in range(2, PRIME_LENGTH):
    if not prime_list[i]:
        idx = i
        while idx < PRIME_LENGTH:
            prime_list[idx].append(i)
            idx += i

vote = [0] * (PRIME_LENGTH)

for a in A:
    for v in prime_list[a]:
        vote[v] += 1

if max(vote) == len(A):
    print("not coprime")
elif sum(map(lambda x: x > 1, vote)) > 0:
    print("setwise coprime")
else:
    print("pairwise coprime")


Fixed submission:
N = int(input())
A = [int(s) for s in input().split()]

PRIME_LENGTH = 10**6 + 1

prime_list = [[] for _ in range(PRIME_LENGTH)]

for i in range(2, PRIME_LENGTH):
    if not prime_list[i]:
        idx = i
        while idx < PRIME_LENGTH:
            prime_list[idx].append(i)
            idx += i

vote = [0] * (PRIME_LENGTH)

for a in A:
    for v in prime_list[a]:
        vote[v] += 1

if max(vote) == len(A):
    print("not coprime")
elif sum(map(lambda x: x > 1, vote)) > 0:
    print("setwise coprime")
else:
    print("pairwise coprime")