alexjercan/bugnet huggingface dataset:
Problem p02574 (C++) — buggy submission, verdict: 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>;

const int A = 1000005;

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

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

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

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

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int gcds(vector<int> as) {
  int ans = as[0];
  for (int i = 1; i < (int)as.size(); i++) {
    ans = gcd(ans, as[i]);
  }
  return ans;
}

const int MAX = 100005;
int main() {
  int n;
  cin >> n;
  int m = 0;
  vector<int> as(n);
  vector<int> cnts(MAX, 0);
  rep(i, n) {
    cin >> as[i];
    m = max(as[i], m);
    cnts[as[i]]++;
  }
  bool isPair = true;
  for (int i = 2; i <= m; i++) {
    int cnt = 0;
    for (int j = i; j <= m; j += i) {
      cnt += cnts[i];
    }
    if (1 < cnt) {
      isPair = false;
    }
  }
  if (isPair) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = gcds(as);
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

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

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
typedef long long ll;
int prime[maxn + 1];
int vis[maxn + 1];
void Prime() {
  memset(vis, 0, sizeof(vis));
  memset(prime, 0, sizeof(prime));
  for (int i = 2; i <= maxn; i++) {
    //        cout<<" i = "<<i<<endl;
    if (!vis[i]) {
      prime[++prime[0]] = i; // 纪录素数， 这个prime[0] 相当于 cnt，用来计数
    }
    for (int j = 1; j <= prime[0] && i * prime[j] <= maxn; j++) {
      //            cout<<"  j = "<<j<<" prime["<<j<<"]"<<" = "<<prime[j]<<"
      //            i*prime[j] = "<<i*prime[j]<<endl;
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
}
int n, a[maxn];
int num[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  Prime();
  bool f = true;
  for (int i = 1; i <= n; i++) {
    int p = a[i];
    for (int j = 1; j <= prime[0] && p >= prime[j]; j++) {
      if (p % prime[j] == 0) {
        if (num[prime[j]])
          f = false;
        num[prime[j]] = 1;
        while (p % prime[j] == 0)
          p /= prime[j];
        if (p == 1)
          break;
      }
      if (!vis[p]) {
        if (num[p])
          f = false;
        num[p] = 1;
        break;
      }
    }
  }
  int gcd = a[1];
  for (int i = 2; i <= n; i++)
    gcd = __gcd(gcd, a[i]);
  if (f)
    printf("pairwise coprime\\n");
  else if (!f && gcd == 1)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7, mod = 1e9 + 7;
typedef long long ll;
vector<int> v;
int ar[maxn];
void prime() {
  for (int i = 2; i < 1e6 + 1; i++)
    ar[i] = 1;
  for (int i = 2; i * i < 1e6 + 1; i++) {
    if (ar[i]) {
      for (int j = i * i; j < 1e6 + 1; j += i)
        ar[j] = 0;
    }
  }
  for (int i = 2; i < 1e6 + 1; i++) {
    if (ar[i])
      v.push_back(i);
  }
}
int n, a[maxn];
map<int, int> mp;
int main() {
  scanf("%d", &n);
  int gcd = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), gcd = __gcd(gcd, a[i]);
  prime();
  bool f = false;
  for (int i = 1; i <= n && !f; i++) {
    for (int j = 0; j < v.size() && !f; j++) {
      if (a[i] % v[j] == 0) {
        if (mp.count(v[j]))
          f = true;
        mp[v[j]]++;
      }
    }
  }
  if (!f)
    printf("pairwise coprime\\n");
  else if (f && gcd == 1)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
}
Problem p02574 (C++) — buggy submission, verdict: 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(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;
}

Error: -11

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(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;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int f2 = 0;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> arr(maxn, 0);
  for (auto x : a) {
    arr[x] += 1;
    f2 = __gcd(f2, x);
  }
  int f1 = 1;
  // sort(a.begin(),a.end());
  for (int i = 2; i < maxn; i++) {
    int ct = 0;
    for (int j = i; j < maxn; j += i) {
      ct += arr[j];
    }
    f1 = f1 & (ct <= 1);
  }

  if (f1 == 1) {
    cout << "pairwise coprime" << endl;
  } else if (f2 == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}


Error: 1

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int f2 = 0;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    // arr[a[i]]+=1;
    // f2=__gcd(f2,a[i]);
  }
  vector<int> arr(maxn, 0);
  for (auto x : a)
    arr[x] += 1;
  int f1 = 1;
  // sort(a.begin(),a.end());
  for (int i = 2; i < maxn; i++) {
    int ct = 0;
    // for(int j=i;j<maxn;j+=i){
    //        ct+=arr[j];
    //}
    f1 = f1 & (ct <= 1);
  }

  if (f1 == 1) {
    cout << "pairwise coprime" << endl;
  } else if (f2 == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "Yes\\n"
#define N cout << "No\\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i, n) for (int i = 0; i < n; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)

long long mod = 1000000007, ans = 1;

int prime[1000010];
void fun() {
  prime[1] = 1;
  for (int i = 2; i < 1000001; i++) {
    if (prime[i] == 0) {
      for (int j = i; j < 1000001; j += i) {
        prime[j] = i;
      }
    }
  }
}
bool p[1000001];
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fun();
  int n, m, a[1000010] = {0};
  cin >> n;
  R(i, n) {
    cin >> a[i];
    if (i > 0) {
      m = gcd(a[i], m);
    } else {
      m = a[i];
    }
  }
  if (m > 1) {
    cout << "not coprime\\n";
  } else {
    int f = 0;
    R(i, n) {
      while (a[i] > 1) {
        int x = prime[a[i]];
        while (1) {
          if (a[i] % x == 0) {
            a[i] /= x;
          } else {
            break;
          }
        }
        if (p[x] != 0) {
          f = 1;
          break;
        } else {
          p[x] = 1;
        }
      }
    }
    if (f == 0) {
      cout << "pairwise coprime\\n";
    } else {
      cout << "setwise coprime\\n";
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "Yes\\n"
#define N cout << "No\\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i, n) for (int i = 0; i < n; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)

long long mod = 1000000007, ans = 1;

int prime[1000010];
void fun() {
  prime[1] = 1;
  for (int i = 2; i < 1000001; i++) {
    if (prime[i] == 0) {
      for (int j = i; j < 1000001; j += i) {
        prime[j] = i;
      }
    }
  }
}
bool p[1000001];
int gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fun();
  int n, m, a[200010] = {0};
  cin >> n;
  R(i, n) {
    cin >> a[i];
    if (i > 0) {
      m = gcd(a[i], m);
    } else {
      m = a[i];
    }
  }
  if (m > 1) {
    cout << "not coprime\\n";
  } else {
    int f = 0;
    R(i, n) {
      while (a[i] > 1) {
        int x = prime[a[i]];
        while (1) {
          if (a[i] % x == 0) {
            a[i] /= x;
          } else {
            break;
          }
        }
        if (p[x] != 0) {
          f = 1;
          break;
        } else {
          p[x] = 1;
        }
      }
    }
    if (f == 0) {
      cout << "pairwise coprime\\n";
    } else {
      cout << "setwise coprime\\n";
    }
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
typedef long long ll;
ll gcd(ll _a, ll _b) {
  unsigned long long a = abs(_a), b = abs(_b);
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  int shift = __builtin_ctzll(a | b);
  a >>= __builtin_ctzll(a);
  do {
    b >>= __builtin_ctzll(b);
    if (a > b)
      std::swap(a, b);
    b -= a;
  } while (b);
  return (a << shift);
}

int cnt[1000001];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int num;
    scanf("%d", &num);
    cnt[num]++;
  }
  int max_S = 0;
  for (int i = 2; i <= 1000000; i++) {
    int S = 0;
    for (int j = i; j <= 1000000; j += i)
      S += cnt[j];
    max_S = std::max(max_S, S);
  }
  if (max_S < 2)
    printf("pairwise coprime\\n");
  else if (max_S != n)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
}


Error: 0

Fixed submission:

#include <iostream>

inline int gcd(int a, int b) {
  if (b < a)
    std::swap(a, b);
  int r = a % b;
  if (r == 0)
    return b;
  while (r != 0)
    r = a % b, a = b, b = r;
  return a;
}

int cnt[1000001];

int main() {
  int n;
  scanf("%d", &n);
  if (n > 78498) {
    int g;
    scanf("%d", &g);
    for (int i = 1; i < n; i++) {
      int k;
      scanf("%d", &k);
      g = gcd(g, k);
    }
    exit(1);
    if (g == 1)
      printf("setwise coprime\\n");
    else
      printf("not coprime\\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int num;
    scanf("%d", &num);
    cnt[num]++;
  }
  int max_S = 0;
  for (int i = 2; i <= 1000000; i++) {
    int S = 0;
    for (int j = i; j <= 1000000; j += i)
      S += cnt[j];
    max_S = std::max(max_S, S);
  }
  if (max_S < 2)
    printf("pairwise coprime\\n");
  else if (max_S != n)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long n;
  cin >> n;
  vector<long> a(n), eras(1e6 + 1, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 2; i <= 1e6; i++)
    if (eras[i] == 0) {
      eras[i] = i;
      for (int j = 2; i * j <= 1e6; j++)
        if (eras[i * j] == 0)
          eras[i * j] = i;
    }

  vector<long> alle(1e6 + 1, 0);
  for (int i = 0; i < n; i++) {
    if (a[i] == 1)
      continue;
    long ai = a[i];
    do {
      alle[eras[ai]]++;
      for (long d = eras[ai]; ai % d == 0;)
        ai /= d;
      //      ai /= eras[ai];
    } while (ai != 1);
  }

  string ans = "pairwise coprime";
  for (int i = 2; i <= 1e6; i++) {
    if (alle[i] == n)
      ans = "not coprime";
    else if (alle[i] > 1 && ans == "pairwise coprime")
      ans = "setwise coprime";
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  long n;
  cin >> n;
  vector<long> a(n), eras(1e6 + 1, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 2; i <= 1e6; i++)
    if (eras[i] == 0) {
      eras[i] = i;
      for (int j = 2; i * j <= 1e6; j++)
        if (eras[i * j] == 0)
          eras[i * j] = i;
    }

  vector<long> alle(1e6 + 1, 0);
  for (int i = 0; i < n; i++) {
    long ai = a[i];
    do {
      alle[eras[ai]]++;
      for (long d = eras[ai]; ai % d == 0;)
        ai /= d;
      //      ai /= eras[ai];
    } while (ai != 1);
  }

  string ans = "pairwise coprime";
  for (int i = 1; i <= 1e6; i++) {
    if (alle[i] == n)
      ans = "not coprime";
    else if (alle[i] > 1 && ans == "pairwise coprime")
      ans = "setwise coprime";
  }

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

#include <iostream>
using namespace std;
#include <algorithm>
#include <map>
#include <string>
#include <vector>
typedef long long ll;
#include <cmath>
#include <iomanip>
#include <set>

ll gcm(ll a, ll b) {
  if (b > a) {
    ll c = a;
    a = b;
    b = c;
  }
  while (b > 0) {
    ll r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  int Gall;

  bool pair = true;
  set<int> Prime;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (i == 0)
      Gall = a;
    else
      Gall = gcm(Gall, a);
    if (pair) {
      for (int x = 2; x * x < a; x++) {
        if (a % x == 0) {
          while (a % x == 0)
            a /= x;
          if (Prime.count(x))
            pair = false;
          else
            Prime.insert(x);
        }
      }
      if (a > 1) {
        if (Prime.count(a))
          pair = false;
        else
          Prime.insert(a);
      }
    }
  }
  if (pair)
    cout << "pairwise coprime" << endl;
  else if (Gall == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#include <algorithm>
#include <map>
#include <string>
#include <vector>
typedef long long ll;
#include <cmath>
#include <iomanip>

const int MOD = 998244353;

ll POWER(ll x, ll y) {
  ll ret = 1;
  ll p = x;
  for (ll i = y; i > 0; i /= 2) {
    if (i % 2)
      ret = (ret * p) % MOD;
    p = (p * p) % MOD;
  }
  return ret;
}
ll gcm(ll a, ll b) {
  if (b > a) {
    ll c = a;
    a = b;
    b = c;
  }
  while (b > 0) {
    ll r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());

  int Gall = a[0];
  for (int i = 1; i < n; i++) {
    Gall = gcm(Gall, a[i]);
  }
  if (Gall > 1) {
    cout << "not coprime" << endl;
    return 0;
  }

  bool pair = true;

  for (int i = 1; i < n; i++) {
    if (pair) {
      for (int j = 0; j < i; j++) {
        if (gcm(a[i], a[j]) > 1) {
          pair = false;
          break;
        }
      }
    }
    if (!pair)
      break;
  }
  if (pair)
    cout << "pairwise coprime" << endl;
  else
    cout << "setwise coprime" << endl;

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

#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007
const int N = 1e6 + 5;
ll cnt[N];
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll gc = a[0];
  for (int i = 1; i < n; i++) {
    gc = gcd(gc, a[i]);
  }
  if (gc > 1) {
    cout << "not coprime";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    ll t = a[i];
    for (int j = 2; j * j <= t; j++) {
      if (t % j == 0) {
        while (t % j == 0) {
          t /= j;
        }
        cnt[j]++;
      }
    }
    if (t > 1) {
      cnt[t]++;
    }
  }
  bool flag = 1;
  for (auto it : cnt) {
    if (it > 1) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime";
  } else {
    cout << "setwise coprime";
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007
const int N = 1e6 + 5;
ll cnt[N];
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll gc = a[0];
  for (int i = 1; i < n; i++) {
    gc = gcd(gc, a[i]);
  }
  if (gc > 1) {
    cout << "not coprime";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    ll t = a[i];
    for (int j = 2; j * j <= a[i]; j++) {
      if (t % j == 0) {
        while (t % j == 0) {
          t /= j;
        }
        cnt[j]++;
      }
    }
    if (t > 1) {
      cnt[t]++;
    }
  }
  bool flag = 1;
  for (auto it : cnt) {
    if (it > 1) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime";
  } else {
    cout << "setwise coprime";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> al(n);
  vector<ll> cop(1000001);
  rep(j, n) {
    cin >> al[j];
    vector<pair<ll, ll>> res = prime_factorize(al[j]);
    rep(i, res.size()) { ++cop[res[i].first]; }
  }
  string ans = "pairwise coprime";
  rep(i, 1000000) {
    if (i <= 1) {
      continue;
    }
    if (cop[i] == n) {
      ans = "not coprime";
      break;
    } else if (cop[i] >= 2) {
      ans = "setwise coprime";
    }
  }
  cout << ans << endl;
  system("pause");
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> al(n);
  vector<ll> cop(1000001);
  rep(j, n) {
    cin >> al[j];
    vector<ll> res(al[j] + 1);
    int num = al[j];
    int pre = 0;
    for (int i = 2; i <= n; i++) {
      while (num % i == 0) {
        if (pre == i) {
          num /= i;
          pre = i;
          continue;
        }
        // res.at(i)++;
        ++cop[i];
        pre = i;
      }
    }
    if (pre != num) {
      ++cop[num];
    }
  }
  string ans = "pairwise coprime";
  rep(i, 1000000) {
    if (i <= 1) {
      continue;
    }
    if (cop[i] == n) {
      ans = "not coprime";
      break;
    } else if (cop[i] >= 2) {
      ans = "setwise coprime";
    }
  }
  cout << ans << endl;
  system("pause");
}