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

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {

  int n;
  cin >> n;

  vector<int> v(n);

  int i, j;
  int maxi = INT_MIN;

  for (i = 0; i < n; i++) {
    cin >> v[i];
    maxi = max(maxi, v[i]);
  }
  int gcd = v[0];

  vector<int> sieve(maxi + 1, -1);

  sieve[1] = 1;

  for (i = 2; i <= maxi; i++) {
    if (sieve[i] != -1)
      continue;

    for (j = i; j <= maxi; j = j + i) {
      if (sieve[j] == -1)
        sieve[j] = i;
    }
  }

  bool f = 1;

  map<int, int> m;

  for (auto it = v.begin(); it != v.end(); it++) {
    int val = *it;
    gcd = __gcd(gcd, val);

    while (val > 1) {
      int x = sieve[val];

      if (x == -1)
        break;
      m[x]++;

      while (val % x == 0)
        val = val / x;
    }
  }

  for (auto it = m.begin(); it != m.end(); it++) {
    if (it->second > 1)
      f = 0;
  }

  if (f == 1) {
    cout << "pairwise coprime" << endl;
    return;
  }
  if (gcd == 1) {
    cout << "setwise coprime" << endl;
    return;
  }

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

int main() {

  int t = 1;
  // cin>>t;

  while (t--)
    solve();

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {

  ll n;
  cin >> n;

  vector<ll> v(n);

  ll i, j;
  set<ll> s;
  ll si = n;
  vector<ll> temp;
  bool one = 0;
  for (i = 0; i < n; i++) {
    cin >> v[i];
    if (v[i] == 1) {
      si--;
      one = 1;
      continue;
    }
    s.insert(v[i]);
  }
  for (auto it = s.begin(); it != s.end(); it++)
    temp.pb(*it);

  bool f = 1;
  bool t = 1;
  ll maxi = temp[temp.size() - 1];

  for (j = 2; j * j <= maxi; j++) {
    int count = 0;
    for (i = 0; i < temp.size(); i++) {
      if (temp[i] % j == 0) {
        count++;
        while (temp[i] % j == 0)
          temp[i] = temp[i] / j;
      }
    }
    if (count > 1)
      f = 0;
    if (count == temp.size())
      t = 0;
    // cout<<count<<endl;
    if (f == 0 && t == 0)
      break;
  }

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

  if (t == 1 || one == 1) {
    cout << "setwise coprime";
    return;
  }

  cout << "not coprime";

  return;

  /*

  for(auto it =s.begin();it!=s.end();it++)
  {
      ll val =  *it;

      if(val%2==0)
      {
          m[2]++;
          while(val%2==0)val = val/2;
      }

      for(j=3;j*j<=val;j=j+2)
      {
          if(val%j==0)
          {
              m[j]++;
              while(val%j==0)val = val/j;
          }
      }
  }
  bool f=1;
  int x = s.size();
  if(x!=si)f=0;

  bool t=1;
  for(auto it=m.begin();it!=m.end();it++)
  {
      if(it->second > 1)
      {
          f = 0;
      }
      if(it->second == x)
      t=0;

  }

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

  if(t==1 || si < n)
  {
      cout<<"setwise coprime";
      return;
  }
  cout<<"not coprime";



 return;
 */
}

int main() {

  int t = 1;
  // cin>>t;

  while (t--)
    solve();

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

/// You just can't beat the person who never gives up
/// ICPC next year

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;

int n, a[N];
int spf[N], vis[N], vid;
bool is[N];
void sieve() {
  for (int i = 1; i < N; ++i)
    spf[i] = i;
  for (int i = 2; i * i < N; ++i)
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
}
vector<int> factorize(int x) {
  vector<int> ret;
  ++vid;
  while (x != 1) {
    if (vis[spf[x]] != vid)
      ret.push_back(spf[x]);
    vis[spf[x]] = vid;
    x /= spf[x];
  }
  return ret;
}
int x;
bool Never_give_up() {
  sieve();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    x = __gcd(x, a[i]);
  }
  if (x != 1)
    return cout << "not coprime\\n", 0;
  for (int i = n - 1; i >= 0; --i) {
    auto vec = factorize(a[i]);
    for (int j : vec)
      if (is[j])
        return cout << "setwise coprime\\n", 0;
    for (int j : vec)
      is[j] = 1;
  }
  cout << "pairwise coprime\\n";
  return 0;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // std::ios::sync_with_stdio(0);
  // cin.tie(0) ,cout.tie(0);
  int t = 1;
  // scanf("%d",&t);
  while (t--) {
    Never_give_up();
  }
  return 0;
}


Error: WA

Fixed submission:

/// You just can't beat the person who never gives up
/// ICPC next year

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;

int n, a[N];
int spf[N], vis[N], vid;
bool is[N];
void sieve() {
  for (int i = 1; i < N; ++i)
    spf[i] = i;
  for (int i = 2; i * i < N; ++i)
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
}
vector<int> factorize(int x) {
  vector<int> ret;
  ++vid;
  while (x != 1) {
    if (vis[spf[x]] != vid)
      ret.push_back(spf[x]);
    vis[spf[x]] = vid;
    x /= spf[x];
  }
  return ret;
}
int x;
bool Never_give_up() {
  sieve();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    x = __gcd(x, a[i]);
  }
  if (x != 1)
    return cout << "not coprime\\n", 0;
  for (int i = n - 1; i >= 0; --i) {
    auto vec = factorize(a[i]);
    for (int j : vec)
      if (is[j])
        return cout << "setwise coprime\\n", 0;
    for (int j : vec)
      is[j] = 1;
  }
  cout << "pairwise coprime\\n";
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // std::ios::sync_with_stdio(0);
  // cin.tie(0) ,cout.tie(0);
  int t = 1;
  // scanf("%d",&t);
  while (t--) {
    Never_give_up();
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int b[N], a[N], q[N], v[N];

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  scanf("%d", &n);
  int flag1 = 0, flag2 = 0;
  unordered_map<int, int> primes;
  for (int i = 0; i < n; i++) {

    scanf("%d", &a[i]);
    b[i] = a[i];
    for (int j = 2; j <= a[i] / j; j++) {
      int c = 1;
      while (a[i] % j == 0) {
        a[i] /= j;
        if (c) {
          c = 0;
          primes[j]++;
          if (primes[j] > 1)
            flag1 = 1;
        }
      }
    }
    if (a[i] > 1)
      primes[a[i]]++;
    if (primes[a[i]] > 1)
      flag1 = 1;
  }

  for (int i = 0; i < n - 1; i++) {
    b[i + 1] = gcd(b[i], b[i + 1]);
    if (b[i + 1] == 1)
      flag2 = 2;
    // printf("%d\\n",a[i+1]);
  }
  if (!flag1)
    puts("pairwise coprime");
  else if (flag2)
    puts("setwise coprime");
  else
    puts("not coprime");
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], q[N], v[N];
void prime() {

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

    for (int j = i; j <= N / i; j++)
      v[i * j] = 1;
  }
}
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  prime();
  int tests = 1;
  // cin>>tests;
  while (tests--) {
    int x = 0, y = 0, z = 0;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (v[a[i]] == 0) {
        x++;
      }
    }
    for (int i = 0; i < n - 1; i++) {
      a[i + 1] = gcd(a[i], a[i] + 1);
      if (a[i + 1] == 1) {
        y++;
        break;
      }
    }

    if (x == n)
      puts("pairwise coprime");
    else if (y)
      puts("setwise coprime");
    else
      puts("not coprime");
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
#define ALL(a) a.begin(), a.end()
#define rep(i, K, N) for (long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

vector<bool> P;
map<ll, ll> M;

void prime_factor(ll N) {

  bool C = 1;

  while (C) {

    C = 0;

    rep(i, 2, sqrt(N)) {

      if (N % i == 0) {
        M[i]++;
        N /= i;
        C = 1;
        break;
      }
    }
  }

  M[N]++;
}

ll gcd(ll N, ll M) {

  if (N % M == 0)
    return M;

  else
    return gcd(M, N % M);
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> Prime;
  map<ll, bool> m;

  bool C = 0, D = 1;

  rep(i, 0, N) cin >> A[i];

  ll G = A[0];

  rep(i, 0, N) {

    ll a = A[i];

    if (a != 1)
      prime_factor(a);

    for (auto x : M) {

      if (!m[x.first])
        m[x.first] = 1;

      else {
        C = 1;
        break;
      }
    }

    M.clear();

    if (C)
      break;
  }

  rep(i, 0, N - 1) {

    G = gcd(G, A[i + 1]);

    if (G == 1) {
      D = 0;
      break;
    }
  }

  // cout << G << endl;
  // for(auto x : M)cout << x.first << " " << x.second << endl;

  if (!C)
    cout << "pairwise coprime";
  else {

    if (D)
      cout << "not coprime";

    else
      cout << "setwise coprime";
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define ALL(a) a.begin(), a.end()
#define rep(i, K, N) for (long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

vector<bool> P;

void F(ll X) {

  P.resize(X + 1);

  rep(i, 2, X + 1) P[i] = 1;

  ll p = 2;

  while (p <= sqrt(X)) {

    ll i = 2;

    while (p * i <= X) {

      P[p * i] = 0;
      i++;
    }

    p++;
  }
}

ll gcd(ll N, ll M) {

  if (N % M == 0)
    return M;

  else
    return gcd(M, N % M);
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> Prime;
  map<ll, ll> M;

  F(1000000);

  ll L = P.size();

  rep(i, 0, L) {

    if (P[i])
      Prime.push_back(i);
  }

  bool C = 0;

  rep(i, 0, N) cin >> A[i];

  rep(i, 0, N) {

    ll j = 0;

    while (Prime[j] <= A[i]) {

      if (A[i] % Prime[j] == 0) {

        if (M[Prime[j]] == 0) {
          M[Prime[j]]++;
          j++;
        } else {
          C = 1;
          break;
        }

      }

      else
        j++;
    }

    if (C)
      break;
  }

  ll G = A[0];
  bool D = 1;

  rep(i, 0, N - 1) {

    G = gcd(G, A[i + 1]);

    if (G == 1) {
      D = 0;
      break;
    }
  }

  // cout << G << endl;

  if (!C)
    cout << "pairwise coprime";
  else {

    if (D)
      cout << "not coprime";

    else
      cout << "setwise coprime";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const long long MOD = 1000000007;
const long long inverse2 = 500000004;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> prime(1000001);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i] % 2 == 0) {
      prime[2]++;
    }
    while (A[i] % 2 == 0) {
      A[i] /= 2;
    }
    int j = 3;
    while (j * j <= A[i]) {
      if (A[i] % j == 0) {
        prime[j]++;
      }
      while (A[i] % j == 0) {
        A[i] /= j;
      }
      j += 2;
    }
    if (A[i] > 1) {
      prime[A[i]]++;
    }
  }
  bool pair = true;
  bool set = true;
  for (int i = 2; i <= 1000000; i++) {
    if (prime[i] > 1) {
      pair = false;
    }
    if (prime[i] == n) {
      set = false;
    }
  }
  if (pair) {
    cout << "pairwise coprime" << '\\n';
  } else {
    if (set) {
      cout << "setwise coprime" << '\\n';
    } else {
      cout << "not coprime" << '\\n';
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

const long long MOD = 1000000007;
const long long inverse2 = 500000004;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> prime(1000001);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i] % 2 == 0) {
      prime[2]++;
    }
    while (A[i] % 2 == 0) {
      A[i] /= 2;
    }
    int j = 3;
    while (j <= A[i]) {
      if (A[i] % j == 0) {
        prime[j]++;
      }
      while (A[i] % j == 0) {
        A[i] /= j;
      }
      j += 2;
    }
  }
  bool pair = true;
  bool set = true;
  for (int i = 2; i <= 1000000; i++) {
    if (prime[i] > 1) {
      pair = false;
    }
    if (prime[i] == n) {
      set = false;
    }
  }
  if (pair) {
    cout << "pairwise coprime" << '\\n';
  } else {
    if (set) {
      cout << "setwise coprime" << '\\n';
    } else {
      cout << "not coprime" << '\\n';
    }
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define int long long
#define endl '\\n'

using namespace std;

const int N = 2e6 + 77;
int cnt[N], g;

int32_t main() {
  fast;
  int n;
  cin >> n;
  bool pp = true;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    g = __gcd(g, a);
    cnt[a]++;
  }

  for (int i = 2; i < N; ++i) {
    int sum = 0;
    for (int j = i; j < N; j += i)
      sum += cnt[j];
    if (sum > 1) {
      pp = false;
      break;
    }
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define int long long
#define endl '\\n'

using namespace std;

const int N = 2e5 + 77;
int A[N];

int32_t main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> A[i];
  int g = A[0];
  bool pp = 1, sp = 1;
  for (int i = 1; i < n; ++i) {
    g = __gcd(g, A[i]);
    if (__gcd(A[i], A[i - 1]) != 1)
      pp = false;
  }
  if (g != 1)
    sp = false;
  if (pp)
    cout << "pairwise coprime" << endl;
  else if (sp)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define INIT                                                                   \\
  ios_base ::sync_with_stdio(false);                                           \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[1000010], q, l, r;
bool v[1000010];
int cnt[1000010];

int32_t main() {
  INIT cin >> n;
  int sgcd = 0;
  bool sw = false, pw = true;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sgcd = __gcd(sgcd, a[i]);
  }
  if (sgcd == 1) {
    sw = true;
  }

  for (int i = 2; i <= 1000000; i++) {
    if (!v[i]) {
      int c = 0;
      c += cnt[i];
      for (int j = 2 * i; j <= 1000000; j += i) {
        v[j] = true;
        c += cnt[j];
      }
      if (c > 1) {
        pw = false;
        break;
      }
    }
  }

  if (pw) {
    cout << "pairwise coprime";
  } else {
    if (sw) {
      cout << "setwise coprime";
    } else {
      cout << "not coprime";
    }
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define INIT                                                                   \\
  ios_base ::sync_with_stdio(false);                                           \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[300010], q, l, r;
bool v[1000010];
int cnt[1000010];

int32_t main() {
  INIT cin >> n;
  int sgcd = 0;
  bool sw = false, pw = true;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sgcd = __gcd(sgcd, a[i]);
  }
  if (sgcd == 1) {
    sw = true;
  }

  for (int i = 2; i <= 1000000; i++) {
    if (!v[i]) {
      int c = 0;
      c += cnt[i];
      for (int j = 2 * i; j <= 1000000; j += i) {
        v[j] = true;
        c += cnt[j];
      }
      if (c > 1) {
        pw = false;
        break;
      }
    }
  }

  if (pw) {
    cout << "pairwise coprime";
  } else {
    if (sw) {
      cout << "setwise coprime";
    } else {
      cout << "not coprime";
    }
  }

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

#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 gcd(int a, int b) {
  int x = max(a, b);
  int y = min(a, b);
  int r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}

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 = a[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: TLE

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 gcd(int a, int b) {
  int x = max(a, b);
  int y = min(a, b);
  int r = x % y;

  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}

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

  rep(i, n) {
    cin >> a[i];
    if (a[i] > max_a)
      max_a = a[i];
  }
  max_a += 5;

  //
  bool pairwise = true;
  vector<int> cnt(max_a, 0);
  for (int ai : a) {
    int tmp = ai;
    for (int i = 2; i < max_a; i++) {
      if (tmp % i == 0) {
        cnt[i]++;
        while (tmp % i == 0) {
          tmp /= i;
        }
      }
    }
  }
  for (int i : cnt) {
    if (i >= 2) {
      pairwise = false;
      break;
    }
  }
  if (pairwise) {
    printf("pairwise coprime");
    return 0;
  }

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

  printf("not coprime");

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }              // 最小公倍数
using Graph = vector<vector<int>>;
ll inf = 300000000000000000;
const double PI = 3.14159265358979323846;
int main() {
  int n;
  cin >> n;
  vector<int> k(1000001, 0);
  int u[n];
  rep(i, n) cin >> u[i];
  int g = u[0];
  rep(i, n - 1) { g = gcd(g, u[i + 1]); }
  set<int> s;
  s.insert(2);
  rep(i, 997) {
    int y = i + 3;
    int v = 0;
    rep(j, y - 2) {
      if (y % (j + 2) == 0)
        v++;
    }
    if (v == 0)
      s.insert(y);
  }
  rep(i, n) {
    int a = u[i];
    for (int j : s) {
      if (a % j == 0) {
        k[j]++;
        while (a % j == 0) {
          a /= j;
        }
      }
    }
    if (a > 1)
      k[a]++;
  }
  int x = 0;
  rep(i, 1000001) { x = max(x, k[i]); }
  // rep(i,10)cout << k[i] << endl;
  if (x <= 1) {
    cout << "pairwise coprime" << endl;
  } else if (g == 1) {
    cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }              // 最小公倍数
using Graph = vector<vector<int>>;
ll inf = 300000000000000000;
const double PI = 3.14159265358979323846;
int main() {
  int n;
  cin >> n;
  vector<int> k(1000001, 0);
  int u[n];
  rep(i, n) cin >> u[i];
  int g = u[0];
  rep(i, n - 1) { g = gcd(g, u[i + 1]); }
  rep(i, n) {
    int a = u[i];
    rep(j, 1000) {
      if (j == 0)
        continue;
      if (a % (j + 1) == 0) {
        k[j + 1]++;
        while (a % (j + 1) == 0) {
          a /= (j + 1);
        }
      }
    }
    if (a > 1)
      k[a]++;
  }
  int x = 0;
  rep(i, 1000001) { x = max(x, k[i]); }
  if (x <= 1) {
    cout << "pairwise coprime" << endl;
  } else if (g == 1) {
    cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
}