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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#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 pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template <typename T> struct Edge {
  int u, v;
  T cost;
  Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
  bool operator<(const Edge &e) const { return cost < e.cost; }
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18 + 99);
static const int MAX = 1000000;

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

ll ans;

int main(void) {
  int N;
  cin >> N;
  vector<ll> A(N, 0);
  rep(i, 0, N) cin >> A[i];

  ll g = A[0];
  rep(i, 0, N) g = gcd(g, A[i]);

  if (g != 1) {
    puts("not coprime");
    return 0;
  }

  vector<bool> x(MAX + 5, false);
  rep(i, 0, N) x[A[i]] = true;

  rep(i, 2, MAX + 1) {
    int cnt = 0;
    for (int j = i; j <= MAX; j += i) {
      if (x[j])
        cnt++;
    }
    if (cnt > 1) {
      puts("setwise coprime");
      return 0;
    }
  }

  puts("pairwise coprime");
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#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 pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template <typename T> struct Edge {
  int u, v;
  T cost;
  Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
  bool operator<(const Edge &e) const { return cost < e.cost; }
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18 + 99);
static const int MAX = 20;

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

ll ans;

int main(void) {
  int N;
  cin >> N;
  vector<ll> A(N, 0);
  rep(i, 0, N) cin >> A[i];

  ll g = A[0];
  rep(i, 0, N) g = gcd(g, A[i]);

  if (g != 1) {
    puts("not coprime");
    return 0;
  }

  sort(all(A));

  vector<bool> x(MAX, false);
  rep(i, 0, N) x[A[i]] = true;

  rep(i, 2, MAX + 1) {
    int cnt = 0;
    for (int j = i; j <= MAX; j += i) {
      if (x[j])
        cnt++;
    }
    if (cnt > 1) {
      puts("setwise coprime");
      return 0;
    }
  }

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

#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;

  map<int, int> mp;
  rep(i, 0, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        mp[j]++;
        if (mp[j] > 1) {
          p = 0;
          break;
        }
        while (q % j == 0) {
          q /= j;
        }
      }
    }
    mp[q]++;
    if (q != 1 && mp[q] > 1)
      p = 0;
    if (!p)
      break;
  }
  if (p) {
    for (auto m : mp) {
      if (m.first != 1 && m.second > 1)
        p = 0;
    }
  }

  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";
  }
}

Error: TLE

Fixed submission:

#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;

  map<int, int> mp;
  rep(i, 0, n) {
    int q = a[i];
    for (int j = 2; j * j <= q; j++) {
      if (q % j == 0) {
        mp[j]++;
        while (q % j == 0) {
          q /= j;
        }
      }
    }
    for (auto m : mp) {
      if (m.first != 1 && m.second > 1)
        p = 0;
    }
    if (!p)
      break;
    mp[q]++;
  }
  for (auto m : mp) {
    if (m.first != 1 && m.second > 1)
      p = 0;
  }

  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, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
long long prime[1000003], cnt;
bool v[1000003];
void init(int n) {
  v[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!v[i])
      prime[++cnt] = i;
    for (int j = 1; j <= cnt && i * prime[j] <= n; ++j) {
      v[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
bool f[1000003];
map<int, int> mp;
int main() {
  init(10000);
  int n = read(), xx = read(), x = xx;
  for (int i = 1; i <= cnt; i++)
    if (x % prime[i] == 0) {
      f[i] = 1;
      while (x % prime[i] == 0)
        x /= prime[i];
    }
  bool qwq = 1;
  mp[x] = 1;
  for (int i = 2; i <= n; i++) {
    int zkak = read(), t = zkak;
    if (qwq && t > 1) {
      for (int j = 1; j <= cnt; j++)
        if (t % prime[j] == 0)
          if (f[j])
            qwq = 0;
          else {
            f[j] = 1;
            while (t % prime[j] == 0)
              t /= prime[j];
          }
      if (t > 1)
        if (mp[t])
          qwq = 0;
        else
          mp[t] = 1;
    }
    xx = __gcd(zkak, xx);
  }
  if (qwq)
    puts("pairwise coprime");
  else if (xx == 1)
    puts("setwise coprime");
  else
    puts("not coprime");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
long long prime[1000003], cnt;
bool v[1000003];
void init(int n) {
  v[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!v[i])
      prime[++cnt] = i;
    for (int j = 1; j <= cnt && i * prime[j] <= n; ++j) {
      v[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
bool f[1000003];
int main() {
  init(1000000);
  int n = read(), x = read();
  for (int i = 1; i <= cnt; i++)
    if (x % prime[i] == 0)
      f[i] = 1;
  bool qwq = 1;
  for (int i = 2; i <= n; i++) {
    int t = read();
    if (qwq)
      for (int j = 1; j <= cnt; j++)
        if (t % prime[j] == 0)
          if (f[j])
            qwq = 0;
          else
            f[j] = 1;
    x = __gcd(t, x);
  }
  if (qwq)
    puts("pairwise coprime");
  else if (x == 1)
    puts("setwise coprime");
  else
    puts("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;
typedef long long ll;
typedef pair<int, int> P;

bool sosu[1000005];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  for (int i = 2; i < 1000001; i++) {
    if (sosu[i])
      continue;
    for (int j = i + i; j < 1000001; j += j) {
      sosu[j] = true;
    }
  }

  vector<int> a(N);
  rep(i, N) { a[i] = A[i]; }
  bool check = true;
  for (int i = 2; i < 1001; i++) {
    if (!sosu[i]) {
      int cnt = 0;
      for (int j = 0; j < N; j++) {
        if (a[j] % i == 0) {
          cnt++;
          a[j] /= i;
        }
      }
      if (cnt > 1) {
        check = false;
      }
    }
  }

  vector<int> test(1000005);
  rep(i, N) {
    if (a[i] != 1) {
      test[a[i]]++;
    }
  }

  rep(i, 1000001) {
    if (test[i] > 1) {
      check = false;
    }
  }

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

  int now = A[0];
  for (int i = 1; i < N; i++) {
    now = __gcd(now, A[i]);
  }
  if (now == 1) {
    cout << "setwise coprime" << endl;
  } else {
    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;
typedef long long ll;
typedef pair<int, int> P;

bool sosu[1000005];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  for (int i = 2; i < 1000001; i++) {
    if (sosu[i])
      continue;
    for (int j = i + i; j < 1000001; j += j) {
      sosu[j] = true;
    }
  }

  bool check = true;
  for (int i = 2; i < 1000001; i++) {
    if (!sosu[i]) {
      int cnt = 0;
      for (int j = 0; j < N; j++) {
        if (A[j] % i == 0)
          cnt++;
      }
      if (cnt > 1) {
        check = false;
      }
    }
  }

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

  int now = A[0];
  for (int i = 1; i < N; i++) {
    now = __gcd(now, A[i]);
  }
  if (now == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

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

#include <cstdio>
#include <iostream>
using namespace std;
const int MAXN = 1e6 + 10;
int n, pr[MAXN], a[MAXN];
void div(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      pr[i] += 1;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    pr[x] += 1;
}
int main() {
  //	freopen("in.txt", "r", stdin);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    div(a[i]);
  }
  int flag = 0;
  for (int i = 1; i <= 1e6; i++) {
    if (pr[i] > 1)
      flag = 1;
    if (pr[i] == n) {
      flag = 2;
      break;
    }
  }
  if (flag == 0)
    printf("pairwise coprime\\n");
  else if (flag == 1)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int a[1000050], n;
int gcd(int a, int b) {
  if (!b) {
    return a;
  }
  if (a > b)
    swap(a, b);
  return gcd(a, b % a);
}

bool ipc() {
  for (int i = 1; i <= n - 1; i++)
    for (int j = i + 1; j <= n; j++) {
      if (gcd(a[i], a[j]) != 1)
        return false;
    }
  return true;
}
bool isc() {
  int k = a[1], m;
  for (int i = 2; i <= n; i++) {
    m = gcd(k, a[i]);
    k = m;
    if (k == 1)
      return true;
  }
  return false;
}

int main() {
  // freopen("","r",stdin);
  // freopen("","w",stdout);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  if (!isc()) {
    cout << "not coprime";
    return 0;
  }

  if (ipc()) {
    cout << "pairwise coprime";
    return 0;
  }
  // if(isc()){
  cout << "setwise coprime";
  return 0;
  //}

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

#include <bits/stdc++.h>
#define NN 1000007
bool is_prime[NN];
std::vector<int> primes;
int gcd(int a, int b) { return !a ? b : gcd(b % a, a); }
void sieve() {
  for (int x = 2; x < NN; x++) {
    if (!is_prime[x]) {
      primes.push_back(x);
      for (int z = x + x; z < NN; z += x) {
        is_prime[z] = 1;
      }
    }
  }
}
std::set<int> factors(int number) {
  std::set<int> fa;
  int q = 0;
  int f = primes[q];
  while (f * f <= number) {
    while (number % f == 0) {
      fa.insert(f);
      number /= f;
    }
    f = primes[++q];
  }
  if (number != 1)
    fa.insert(number);

  return fa;
}
int main() {
  sieve();
  int num;
  std::cin >> num;
  std::vector<int> arr;
  for (int x = 0; x < num; x++) {
    int l;
    std::cin >> l;
    arr.push_back(l);
  }
  std::map<int, int> mp;
  for (auto x : arr) {
    std::set<int> st = factors(x);
    for (auto z : st)
      mp[z]++;
  }
  bool tr = true;
  for (auto x : mp) {
    if (x.second > 1) {
      tr = false;
      break;
    }
  }
  if (tr) {
    std::cout << "pairwise coprime";
    return 0;
  }
  int secondPlane = arr[0];
  for (int x = 1; x < num; x++) {
    secondPlane = gcd(secondPlane, arr[x]);
  }
  if (secondPlane == 1)
    std::cout << "setwise coprime";
  else {
    std::cout << "not coprime";
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

int a[1000010];

int main() {
  int N;
  cin >> N;
  int i, j;
  for (i = 0; i < N; i++) {
    cin >> a[i];
  }
  int temp = a[0];

  int flag = 1;
  int gcdall = 0;
  for (i = 0; i < N; i++) {
    for (j = i + 1; j < N; j++) {
      if (gcd(a[i], a[j]) == 1)
        gcdall = 1;
      if (gcd(a[i], a[j]) != 1) {
        flag = 0;
        if (i != 0)
          break;
        temp = gcd(temp, a[j]);
      }
    }
    if (i == 0)
      gcdall = temp;
    if (!flag)
      break;
  }

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int i = 0, j, N, p;
  cin >> N;
  long int A[N];
  p = 1;
  cin >> A[i];
  p = A[i];
  for (i = 1; i < N; i++) {
    cin >> A[i];
    p = __gcd(p, A[i]);
  }
  if (p != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<bool> SOSU(1000010, true);
  vector<int> P(1000010, 1);
  for (i = 2; i < (SOSU.size()) - 1; i++) {
    if (SOSU[i]) {
      P[i] = i;
      for (j = 2 * i; j < (SOSU.size()) - 1; j += i) {
        SOSU[j] = false;
        P[j] = i;
      }
    }
  }
  bool B;
  vector<bool> soinsu(P.size(), false);
  vector<int> siyoukinsi(0);
  auto it = find(siyoukinsi.begin(), siyoukinsi.end(), 0);
  int pp = 0, ppp;
  for (i = 0; i < N; i++) {
    while (A[i] != 1) {
      if (pp != P[A[i]]) {
        siyoukinsi.push_back(pp);
      }
      it = find(siyoukinsi.begin(), siyoukinsi.end(), P[A[i]]);
      if (it != siyoukinsi.end()) {
        cout << "setwise coprime" << endl;
        return 0;
      }
      pp = P[A[i]];
      A[i] /= P[A[i]];
    }
    siyoukinsi.push_back(pp);
    pp = 0;
  }
  cout << "pairwise coprime" << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int i = 0, j, N, p;
  cin >> N;
  long int A[N];
  p = 1;
  cin >> A[i];
  p = A[i];
  for (i = 1; i < N; i++) {
    cin >> A[i];
    p = __gcd(p, A[i]);
  }
  if (p != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<bool> SOSU(1000100, true);
  vector<int> P;
  for (i = 2; i < (SOSU.size()) - 50; i++) {
    if (SOSU[i]) {
      P.push_back(i);
      for (j = 2 * i; j < (SOSU.size()) - 50; j += i) {
        SOSU[j] = false;
      }
    }
  }
  bool B;
  int pp = P.size();
  for (i = 0; i < N; i++) {
    for (p = 0; p < pp; p++) {
      if (A[i] < P[p]) {
        break;
      }
      B = false;
      while (A[i] % P[p] == 0) {
        A[i] /= P[p];
        B = true;
      }
      if (B) {
        P.erase(P.begin() + p);
        pp--;
      }
    }
    if (A[i] != 1) {
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "pairwise coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: 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 = 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;
}

Error: WA

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

#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;
}


Error: WA

Fixed submission:

#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;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
const int N = 1e6 + 3;
int f[N], g;
int main() {

#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    f[x]++;
  }
  for (int i = 0; i < N; i++) {
    if (f[i])
      g = __gcd(g, i);
  }
  if (g > 1) {
    cout << "not coprime";
    return 0;
  }

  for (int i = 2; i < N; i++) {
    int cur = 0;
    for (int j = i; j < N; j += i)
      if (f[j])
        cur++;
    if (cur > 1) {
      cout << "setwise coprime";
      return 0;
    }
  }
  cout << "pairwise coprime";
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N = 1e6 + 3;
vector<int> p;
vector<bool> prime(N, 1);
bool f[N];
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif
  prime[1] = prime[0] = 0;
  for (int i = 2; i < N; i++) {
    if (!prime[i])
      continue;
    for (int j = i * i; j < N; j += i)
      prime[j] = 0;
  }
  for (int i = 0; i < N; i++)
    if (prime[i])
      p.push_back(i);

  int n;
  cin >> n;
  bool pairwise = 1, setwise = 1;
  vector<int> a(n);
  for (int &i : a)
    cin >> i;

  for (int num : a) {
    for (int i = 0; i < p.size() and p[i] <= num; i++) {
      if (num % p[i] == 0) {
        if (f[p[i]]) {
          pairwise = 0;
          break;
        } else {
          num /= p[i];
          f[p[i]] = 1;
        }
      }
    }
  }
  // for(auto i:a)cout<<i<<" ";
  int g = a[0];
  for (int i : a) {
    // cout<<i<<" "<<g<<"\\n";
    g = __gcd(g, i);
  }
  // cout<<g;
  if (g != 1)
    setwise = 0;

  if (pairwise)
    printf("pairwise coprime");
  else if (!pairwise and setwise)
    printf("setwise coprime");
  else
    printf("not coprime");
}