alexjercan/bugnet huggingface dataset:
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

long long gcd(long long m, long long n) {
  long long temp;
  if (n > m)
    swap(m, n);
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  // sort(ret.begin(),ret.end());
  return ret;
}
int main() {
  ll a, b, c, h, i, j, k, l, m, n, x, y;
  ll ans = 0;

  cin >> n;
  vector<ll> aa(n);
  for (i = 0; i < n; i++)
    cin >> aa[i];
  ans = gcd(aa[0], aa[1]);
  for (i = 2; i < n; i++)
    ans = gcd(ans, aa[i]);
  if (ans > 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<ll> an(1000001);
  bool f = false;
  for (i = 0; i < n; i++) {
    for (j = 1; j * j <= aa[i]; j++) {
      if (aa[i] % j == 0) {
        an[j]++;
        if (j != 1 && an[j] > 1) {
          cout << "setwise coprime" << endl;
          return 0;
        }
        if (j * j != aa[i]) {
          an[aa[i] / j]++;
          if ((aa[i] / j != 1) && (an[aa[i] / j] > 1)) {
            cout << "setwise coprime" << endl;
            return 0;
          }
        }
      }
    }
  }

  cout << "pairwise coprime" << endl;

  return 0;
}


Error: TLE

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

long long gcd(long long m, long long n) {
  long long temp;
  if (n > m)
    swap(m, n);
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  // sort(ret.begin(),ret.end());
  return ret;
}
int main() {
  ll a, b, c, h, i, j, k, l, m, n, x, y;
  ll ans = 0;

  cin >> n;
  vector<ll> aa(n);
  for (i = 0; i < n; i++)
    cin >> aa[i];
  ans = gcd(aa[0], aa[1]);
  for (i = 2; i < n; i++)
    ans = gcd(ans, aa[i]);
  if (ans > 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  vector<ll> an(1000001);
  bool f = false;
  for (i = 0; i < n; i++) {
    for (j = 1; j * j <= aa[i]; j++) {
      if (aa[i] % j == 0) {
        an[j]++;
        if (j != 1 && an[j] > 1)
          f = true;
        if (j * j != aa[i]) {
          an[aa[i] / j]++;
          if ((aa[i] / j != 1) && (an[aa[i] / j] > 1))
            f = true;
        }
      }
    }
  }
  if (f) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "pairwise coprime" << endl;
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> primes(int x) {
  vector<int> ret;
  if (x % 2 == 0) {
    ret.push_back(2);
    while (x % 2 == 0)
      x /= 2;
  }
  for (int i = 3; i * i <= x; i += 2) {
    if (x % i)
      continue;
    while (x % i == 0)
      x /= i;
    ret.push_back(i);
  }
  if (x != 1)
    ret.push_back(x);
  return ret;
}
signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> primes_cnt;
  for (auto &x : A) {
    cin >> x;
    for (auto e : primes(x)) {
      primes_cnt[e]++;
    }
  }

  int ma = 0;
  for (auto p : primes_cnt) {
    ma = max(ma, p.second);
  }

  if (ma == N) {
    cout << "not coprime\\n";
  } else if (ma > 1) {
    cout << "setwise coprime\\n";
  } else {
    cout << "pairwise coprime\\n";
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> primes(int x) {
  vector<int> ret;
  for (int i = 2; i * i <= x; i++) {
    if (x % i)
      continue;
    while (x % i == 0)
      x /= i;
    ret.push_back(i);
  }
  if (x != 1)
    ret.push_back(x);
  return ret;
}
signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> primes_cnt;
  for (auto &x : A) {
    cin >> x;
    for (auto e : primes(x)) {
      primes_cnt[e]++;
    }
  }

  int ma = 0;
  for (auto p : primes_cnt) {
    ma = max(ma, p.second);
  }

  if (ma == N) {
    cout << "not coprime\\n";
  } else if (ma > 1) {
    cout << "setwise coprime\\n";
  } else {
    cout << "pairwise coprime\\n";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 7;
int n, cnt[N], freq[N], x[N], vi[N];

int main() {
#ifdef LOCAL
  freopen("input", "r", stdin);
#endif

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
    freq[x[i]]++;
  }

  for (int i = 0; i < n; i++) {
    if (vi[x[i]])
      continue;
    vi[x[i]] = true;
    for (int j = 1; j * j <= x[i]; j++) {
      if (x[i] % j == 0) {
        if (x[i] / j == j) {
          cnt[j] += freq[x[i]];
        } else {
          cnt[x[i] / j] += freq[x[i]];
          cnt[j] += freq[x[i]];
        }
      }
    }
  }

  bool coprime = true, pairwise = true;

  for (int i = 2; i <= 1000000; i++) {
    if (cnt[i] == n) {
      coprime = false;
      break;
    }
    if (cnt[i] > 1) {
      pairwise = false;
      // break;
    }
  }

  if (!coprime) {
    printf("not coprime\\n");
  } else {
    if (pairwise)
      printf("pairwise ");
    else
      printf("setwise ");
    printf("coprime\\n");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 7;
int n, cnt[N], freq[N], x[N], vi[N];

int main() {
#ifdef LOCAL
  freopen("input", "r", stdin);
#endif

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
    freq[x[i]]++;
  }

  for (int i = 0; i < n; i++) {
    if (vi[x[i]])
      continue;
    vi[x[i]] = true;
    for (int j = 1; j * j <= x[i]; j++) {
      if (x[i] % j == 0) {
        if (x[i] / j == j) {
          cnt[j] += freq[x[i]];
        } else {
          cnt[x[i] / j] += freq[x[i]];
          cnt[j] += freq[x[i]];
        }
      }
    }
  }

  bool coprime = true, pairwise = true;

  for (int i = 2; i < N; i++) {
    if (cnt[i] == n)
      coprime = false;
    if (cnt[i] > 1)
      pairwise = false;
  }

  if (!coprime) {
    printf("not coprime\\n");
  } else {
    if (pairwise)
      printf("pairwise ");
    else
      printf("setwise ");
    printf("coprime\\n");
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IN(type, n)                                                            \\
  type n;                                                                      \\
  cin >> n

void count_num(ll n, unordered_map<ll, ll> &count,
               unordered_map<ll, ll> &over_count) {
  if (over_count.count(n))
    over_count[n]++;
  else {
    count[n]++;
    if (count[n] > 1)
      over_count[n] = count[n];
  }
}

int main() {
  ll MAX = 1000000;
  vector<ll> min_div(MAX + 1, 1);
  for (int i = 2; i <= MAX; ++i) {
    if (min_div[i] == 1) {
      for (int j = i; j <= MAX; j += i) {
        min_div[j] = i;
      }
    }
  }

  IN(ll, N);
  vector<ll> A(N);
  unordered_map<ll, ll> count;
  unordered_map<ll, ll> over_count;
  REP(i, N) {
    IN(ll, A);
    ll tmp_div = 1;
    while (A != 1) {
      if (tmp_div != min_div[A]) {
        tmp_div = min_div[A];
        count_num(tmp_div, count, over_count);
      }
      A /= tmp_div;
    }
  }

  if (over_count.size() == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  bool is_pairwise = true;
  for (auto itr = over_count.begin(), itr_end = over_count.end();
       itr != itr_end; ++itr) {
    if (itr->second == N) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IN(type, n)                                                            \\
  type n;                                                                      \\
  cin >> n

void count_num(ll n, unordered_map<ll, ll> &count,
               unordered_map<ll, ll> &over_count) {
  if (over_count.count(n))
    over_count[n]++;
  else {
    count[n]++;
    if (count[n] > 1)
      over_count[n] = count[n];
  }
}

int main() {
  IN(ll, N);
  vector<ll> A(N);
  unordered_map<ll, ll> count;
  unordered_map<ll, ll> over_count;
  REP(i, N) {
    IN(ll, A);
    if (A != 1)
      count_num(A, count, over_count);
    for (ll i = 2; i * i <= A; ++i) {
      if (A % i == 0) {
        count_num(i, count, over_count);
        if (i * i != A) {
          ll tmpA = A / i;
          count_num(tmpA, count, over_count);
        }
      }
    }
  }

  if (over_count.size() == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  bool is_pairwise = true;
  for (auto itr = over_count.begin(), itr_end = over_count.end();
       itr != itr_end; ++itr) {
    if (itr->second == N) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;

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

#include <bits/stdc++.h>

using namespace std;

int MAX = 1e6;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<bool> dp(MAX, false);
  vector<bool> pr(MAX, true);
  vector<int> D(MAX);
  D[1] = 1;
  for (int i = 2; i < MAX; i++) {
    if (pr[i]) {
      D[i] = i;
      for (int j = i; j < MAX / i; j++) {
        D[i * j] = i;
        pr[i * j] = false;
      }
    }
  }
  vector<int> prime;
  int gcd;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];

    if (i == 0)
      gcd = a[0];
    else
      gcd = __gcd(gcd, a[i]);

    if (!ok && a[i] > 1) {
      int p = D[a[i]];
      while (p > 1) {

        auto it = find(prime.begin(), prime.end(), p);
        if (it == prime.end())
          prime.push_back(p);
        else {
          ok = true;
          break;
        }
        while (a[i] % p == 0)
          a[i] /= p;
        p = D[a[i]];
      }
    }
  }
  // for (int a : prime) cout << a << " ";
  // cout << '\\n';
  if (gcd > 1)
    cout << "not coprime" << '\\n';
  else if (ok)
    cout << "setwise coprime" << '\\n';
  else
    cout << "pairwise coprime" << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int MAX = 1e6;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<bool> dp(MAX, false);
  vector<bool> pr(MAX, true);
  vector<int> prime;
  for (int i = 2; i < MAX; i++) {
    if (pr[i]) {
      prime.push_back(i);
      for (int j = i; j < MAX / i; j++)
        pr[i * j] = false;
    }
  }
  int s = prime.size();
  int gcd;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];

    if (i == 0)
      gcd = a[0];
    else
      gcd = __gcd(gcd, a[i]);

    if (!ok) {
      for (int j = 0; j < s; j++) {
        if (prime[j] > a[i])
          break;
        if (a[i] % prime[j] == 0) {
          if (dp[prime[j]]) {
            ok = true;
            break;
          } else
            dp[prime[j]] = true;
        }
      }
    }
  }
  if (gcd > 1)
    cout << "not coprime" << '\\n';
  else if (ok)
    cout << "setwise coprime" << '\\n';
  else
    cout << "pairwise coprime" << '\\n';
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1e6 + 10;
int b[N], r[N];
bool a[N];
int t;
inline int gcd(int x, int y) {
  if (!y)
    return x;
  if (x < y)
    swap(x, y);
  return gcd(y, x % y);
}
inline void fj(int x) {
  for (int i = 1; x != 1 && i <= t; i++)
    if (!a[x]) {
      b[x]++;
      return;
    } else if (x % r[i] == 0) {
      if (x % r[i] == 0)
        b[r[i]]++;
      while (x % r[i] == 0)
        x /= r[i];
    }
}
int main() {
  a[0] = a[1] = true;
  for (int i = 2; i < N; i++)
    if (!a[i]) {
      r[++t] = i;
      for (int j = 2; j * i < N; j++)
        a[i * j] = true;
    }
  int n;
  cin >> n;
  int x;
  scanf("%d", &x);
  fj(x);
  int k = x;
  for (int i = 1; i < n; i++) {
    scanf("%d", &x);
    fj(x);
    k = gcd(k, x);
  }
  if (k != 1) {
    cout << "not coprime\\n";
    return 0;
  }
  for (int i = 1; i <= t; i++)
    if (b[r[i]] > 1) {
      cout << "setwise coprime\\n";
      return 0;
    }
  cout << "pairwise coprime\\n";
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1e6 + 10;
int b[N], r[N];
bool a[N];
int t;
inline void fj(int x) {
  int i = 2;
  for (int i = 1; x != 1 && i <= t; i++) {
    if (x % r[i] == 0)
      b[r[i]]++;
    while (x % r[i] == 0)
      x /= r[i];
  }
}
int main() {
  a[0] = a[1] = true;
  for (int i = 2; i < N; i++)
    if (!a[i]) {
      r[++t] = i;
      for (int j = 2; j * i < N; j++)
        a[i * j] = true;
    }
  int n;
  cin >> n;
  int x;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    fj(x);
  }
  for (int i = 1; i < N; i++)
    if (b[i] == n) {
      cout << "not coprime\\n";
      return 0;
    }
  for (int i = 1; i < N; i++)
    if (b[i] > 1) {
      cout << "setwise coprime\\n";
      return 0;
    }
  cout << "pairwise coprime\\n";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define fr(i, n) for (ll i = 0; i < n; i++)
using namespace std;
const ll A = 1000005;
ll k[A], j[A];
ll n;
bool pairwise() {
  for (ll i = 2; i < A; i++) {
    int cnt = 0;

    for (ll ii = i; ii < A; ii += i) {
      cnt += j[ii];
    }
    if (cnt > 1) {
      return false;
    }
  }
  return true;
}

bool setwise() {
  ll gcd = k[0];
  for (ll i = 1; i < n; i++) {
    gcd = __gcd(k[i], gcd);
    {
      if (gcd == 1)
        return true;
    }
  }
  return false;
}

int main() {
  cin >> n;
  fr(i, n) cin >> k[i], j[k[i]]++;
  if (pairwise())
    cout << "pairwise coprime";
  else if (setwise())
    cout << "setwise coprime";
  else
    cout << "not coprime";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define fr(i, n) for (ll i = 0; i < n; i++)
using namespace std;
ll k[1000005];
ll n;
bool pairwise() {
  for (ll i = 0; i < n; i++) {
    for (ll ii = i + 1; ii < n; ii++) {
      if (__gcd(k[i], k[ii]) != 1)
        return false;
    }
  }
  return true;
}

bool setwise() {
  ll gcd = k[0];
  for (ll i = 1; i < n; i++) {
    gcd = __gcd(k[i], gcd);
    {
      if (gcd == 1)
        return true;
    }
  }
  return false;
}

int main() {
  cin >> n;
  fr(i, n) cin >> k[i];
  if (pairwise())
    cout << "pairwise coprime";
  else if (setwise())
    cout << "setwise coprime";
  else
    cout << "not coprime";
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long int n, a[1000001];
int gcd(int c, int d) { return d == 0 ? c : gcd(d, c % d); }
int main() {
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
    ans = gcd(ans, x);
  }
  int ok = 1;
  for (int i = 2; i <= 1000000; i++) {
    int cnt = 0;
    for (int j = i; j <= 1000000; j += i)
      cnt += a[j];
    if (cnt > 1)
      ok = 0;
  }
  if (ok)
    cout << "pairwise coprime" << endl;
  else if (ans == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime";

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int a[1000000];
bool t = true;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int n, min = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < min)
      min = a[i];
  }
  int k = 0, b = 0, x = 1;
  for (int i = 1; i < n; i++) {
    x = a[i] - a[i + 1];
    if (t)
      if (a[i] % x == 0 && a[i + 1] % x == 0) {
        t = false;
        cout << "setwise coprime";
      }
  }

  if (t)

    while (x == min) {

      x++;
      for (int i = 1; i <= n; i++)
        if (a[i] % x == 0)
          k++;
      if (k = n) {
        cout << "not coprime";
        x = min;
        t = false;
      }
    }

  if (t)
    cout << "pairwise coprime";
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}
ll arr[1000000 + 1], fact[1000000 + 1];
bool prime[1000000 + 1];

int main() {
  fast;
  ll t = 1;
  // cin>>t;

  while (t--) {
    ll n;
    cin >> n;

    ll ma = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      ma = max(arr[i], ma);
    }

    memset(prime, false, sizeof(prime));

    for (int i = 0; i <= ma; i++)
      fact[i] = i;

    for (int i = 2; i <= ma; i++) {
      if (fact[i] == i)
        for (ll j = 2 * i; j <= ma; j += i) {
          if (fact[j] == j)
            fact[j] = i;
        }
    }

    ll p = 0;
    for (int i = 0; i < n; i++) {

      ll a = arr[i];
      while (a > 1) {
        ll h = fact[a];
        while (fact[a] == h)
          a /= fact[a];

        if (prime[h] == true) {
          p = 1;
          break;
        }
        prime[h] = true;
      }
    }
    if (p == 0) {
      cout << "pairwise coprime";
      return 0;
    }

    p = 0;
    ll a = gcd(arr[0], arr[1]);

    for (int i = 0; i < n - 1; i++)
      a = gcd(arr[i + 1], a);

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mod 1000000007
using namespace std;

int main() {
  fast;
  ll t = 1;
  // cin>>t;

  while (t--) {
    ll n;
    cin >> n;

    ll arr[n];
    ll ma = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      ma = max(arr[i], ma);
    }

    bool prime[ma + 1];
    memset(prime, false, sizeof(prime));

    ll fact[ma + 1];
    memset(fact, 0, sizeof(fact));

    for (int i = 0; i <= ma; i++)
      fact[i] = i;

    for (int i = 2; i <= ma; i++) {
      if (fact[i] == i)
        for (int j = i * i; j <= ma; j += i)
          if (fact[j] == j)
            fact[j] = i;
    }
    ll p = 0;
    for (int i = 0; i < n; i++) {

      ll a = arr[i];
      while (a > 1) {
        ll h = fact[a];
        while (fact[a] == h)
          a /= fact[a];

        if (prime[h] == true) {
          p = 1;
          break;
        }
        prime[h] = true;
      }
    }
    if (p == 0) {
      cout << "pairwise coprime";
      return 0;
    }

    p = 0;
    ll a = __gcd(arr[0], arr[1]);

    for (int i = 0; i < n - 1; i++)
      a = __gcd(arr[i + 1], a);

    if (a == 1)
      cout << "setwise coprime";
    else
      cout << "not prime";
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  vector<long> data(N), o(1000001);
  long flag = 1;
  for (int i = 0; i < N; i++)
    cin >> data.at(i);
  long a;
  for (int i = 0; i < N; i++) {
    a = data.at(i);
    for (int j = 2; j <= sqrt(data.at(i)); j++) {
      if (a % j == 0) {
        o.at(j)++;
        if (o.at(j) >= 2)
          flag = 0;
        while (a % j == 0)
          a /= j;
      }
    }
    if (a != 1)
      o.at(a)++;
    if (o.at(a) >= 2)
      flag = 0;
    if (flag == 0)
      break;
  }
  for (int i = 1; i <= 1000000; i++) {
    if (o.at(i) >= 2)
      flag = 0;
  }
  if (flag == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  long g = data.at(0);
  for (int i = 1; i < N; i++) {
    g = __gcd(g, data.at(i));
  }
  if (g == 1) {
    cout << "setwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  vector<long> data(N), o(1000001);
  long flag = 1;
  for (int i = 0; i < N; i++)
    cin >> data.at(i);
  long a;
  for (int i = 0; i < N; i++) {
    a = data.at(i);
    for (int j = 2; j <= sqrt(data.at(i)); j++) {
      if (a % j == 0) {
        o.at(j)++;
        while (a % j == 0)
          a /= j;
      }
    }
    if (a != 1)
      o.at(a)++;
  }
  for (int i = 1; i <= 1000000; i++) {
    if (o.at(i) >= 2)
      flag = 0;
  }
  if (flag == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  long g = data.at(0);
  for (int i = 1; i < N; i++) {
    g = __gcd(g, data.at(i));
  }
  if (g == 1) {
    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;
using ll = long long;
const int N = 1e6 + 1;
vector<bool> primes(N, true);
void soe() {
  for (int i = 2; i * i <= N; ++i) {
    if (primes[i] == true) {
      for (int j = i * i; j < N; j += i)
        primes[j] = false;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  soe();
  int n;
  cin >> n;
  int gc;
  vector<int> freq(1e6 + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    ++freq[x];
    if (i == 1)
      gc = x;
    else
      gc = __gcd(gc, x);
  }
  int flag = 1;
  for (int i = 2; i < N; ++i) {
    if (primes[i]) {
      int cnt = 0;
      for (int j = i; j < N; j += i) {
        cnt += freq[j];
        if (cnt > 1) {
          flag = 0;
          break;
        }
      }
    }
    if (flag == 0)
      break;
  }
  if (flag == 1)
    cout << "pairwise coprime\\n";
  else if (gc == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 1;
bool is_prime[N];
vector<int> primes;
void soe() {
  for (int i = 2; i < N; ++i) {
    is_prime[i] = true;
  }
  for (int i = 2; i * i <= N; ++i) {
    if (is_prime[i] == true) {
      for (int j = i * i; j < N; j += i) {
        is_prime[j] = false;
      }
    }
  }
  for (int i = 2; i < N; ++i) {
    if (is_prime[i] == true)
      primes.push_back(i);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  soe();
  int n;
  cin >> n;
  int arr[n];
  int gc = 1;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    if (i == 0)
      gc = arr[i];
    else
      gc = __gcd(gc, arr[i]);
  }
  int flag = 1;
  map<int, int> mp;
  for (int i = 0; i < (int)primes.size(); ++i) {
    for (int j = 0; j < n; ++j) {
      if (arr[j] % primes[i] == 0) {
        if (mp.count(primes[i]) != 0) {
          flag = 0;
          break;
        } else
          ++mp[primes[i]];
      }
    }
    if (flag == 0)
      break;
  }
  if (flag == 1)
    cout << "pairwise coprime\\n";
  else if (gc == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}