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

#include <bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf printf
using namespace std;
#define ll long long
const int N = 1e6 + 9;
const ll mod = 1e9 + 7;
const ll inf = 2e10;
int prime[N], vis[N];
void seive() {
  for (int i = 1; i < N; i++)
    prime[i] = i;
  for (int i = 2; i < N; i += 2)
    prime[i] = 2;
  for (int i = 3; i * i < N; i += 2) {
    if (prime[i] == i) {
      for (int j = i * i; j < N; j += i) {
        if (prime[j] == j)
          prime[j] = i;
      }
    }
  }
}
vector<int> chk(int v) {
  vector<int> ans;
  while (v != 1) {
    int p = prime[v];
    ans.push_back(p);
    while (v % p == 0)
      v /= p;
  }
  return ans;
}
void slv() {
  seive();
  int n;
  cin >> n;
  int a[n + 3], gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    gcd = __gcd(gcd, a[i]);
  }
  bool ok = 0;
  for (int i = 0; i < n; i++) {
    vector<int> ans = chk(a[i]);
    for (auto x : ans) {
      if (vis[x] == 1)
        ok = 1;
      vis[x] = 1;
    }
    if (ok)
      break;
  }
  if (!ok)
    puts("pairwise coprime");
  else {
    if (gcd == 1)
      puts("setwise coprime");
    else
      puts("not coprime");
  }
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int t;
  t = 1;
  while (t--) {
    slv();
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MAXN 1000005
#define ll long long int
using namespace std;
void seive(int arr[]) {
  arr[1] = 1;
  for (int i = 2; i * i < MAXN; ++i) {
    if (arr[i] == -1) {
      arr[i] = i;
      for (int j = i * i; j < MAXN; j += i) {
        if (arr[j] == -1)
          arr[j] = i;
      }
    }
  }
}
int main() {

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

  int g = __gcd(v[0], v[1]);
  for (int i = 2; i < n; ++i) {
    g = __gcd(g, v[i]);
  }
  if (g != 1) {
    cout << "not coprime\\n";
  } else {
    unordered_map<ll, int> m;
    bool f = true;
    int arr[MAXN];
    memset(arr, -1, sizeof(arr));
    for (int i = 2; i * i < MAXN; ++i) {
      if (arr[i] == -1) {
        arr[i] = i;
        for (int j = i * i; j < MAXN; j += i) {
          if (arr[j] == -1)
            arr[j] = i;
        }
      }
    }
    for (int i = 0; i < n && f; ++i) {
      while (v[i] != 1) {
        if (m.find(arr[v[i]]) != m.end()) {
          if (m[arr[v[i]]] != i) {
            f = false;
            break;
          }
        }
        m[arr[v[i]]] = i;
        v[i] = v[i] / arr[v[i]];
      }
    }
    if (f)
      cout << "pairwise coprime\\n";
    else
      cout << "setwise coprime\\n";
  }
}
Problem p02574 (C++) — buggy submission, verdict: 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 (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";
}

Error: TLE

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 (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, verdict: Runtime Error

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

static const int MAX = 1e6;
int d[MAX + 1];

void eratos(int n) {
  for (int i = 0; i <= n; i++) {
    d[i] = i;
  }
  for (int i = 2; i * i <= n; i++) {
    if (d[i] != i)
      continue;
    for (int j = i + i; j <= n; j += i) {
      if (d[j] != j)
        continue;
      d[j] = i;
    }
  }
}

int main() {
  int n;
  cin >> n;
  eratos(MAX);
  vector<int> cnt(MAX + 1);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    while (a != 1) {
      int pf = d[a];
      cnt[pf]++;
      while (a % pf == 0)
        a /= pf;
    }
  }
  bool nc = false;
  bool sc = false;
  for (int i = 2; i <= MAX; i++) {
    if (cnt[i] >= 2) {
      sc = true;
      if (cnt[i] == n) {
        nc = true;
      }
    }
  }
  if (nc) {
    cout << "not coprime\\n";
  } else if (sc) {
    cout << "setwise coprime\\n";
  } else {
    cout << "pairwise coprime\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

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

static const int MAX = 1e6;
vector<bool> isPrime(MAX + 1, true);
vector<ll> prime;

ll gcd(ll x, ll y) {
  if (x < y)
    return gcd(y, x);
  while (y) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

ll eratos(ll n) {
  isPrime[0] = isPrime[1] = false;
  for (ll i = 2; i * i <= n; i++) {
    if (isPrime[i]) {
      prime.push_back(i);
      ll j = i + i;
      while (j <= n) {
        isPrime[j] = false;
        j += i;
      }
    }
  }
}

int main() {
  ll n;
  cin >> n;
  eratos(1000);
  vector<int> cnt(MAX + 1);
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    for (auto p : prime) {
      if (a % p == 0) {
        cnt[p]++;
      }
    }
  }
  bool nc = false;
  bool sc = false;
  for (auto c : cnt) {
    if (c >= 2) {
      sc = true;
      if (c == n) {
        nc = true;
      }
    }
  }
  if (nc) {
    cout << "not coprime\\n";
  } else if (sc) {
    cout << "setwise coprime\\n";
  } else {
    cout << "pairwise coprime\\n";
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: 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[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;
}


Error: -11

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

/* Ahmed Maher ( Acro_14 ) */
/*while(WA)try();*/
#include <bits/stdc++.h>
typedef long long ll;
const ll oo = 0x3f3f3f3f;
int const N = 1e6 + 5;
int const mod = 1e9 + 7;
using namespace std;
/*string Alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet="abcdefghijklmnopqrstuvwxyz";*/
int fact[1000005];
bool f = false;
void gcd(int x) {
  if (f == true)
    return;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      int a = i;
      int b = x / i;
      if (a == b) {
        a = i;
        b = 1;
      }
      if (a != 1) {
        if (fact[a]) {
          f = true;
          return;
        }
        fact[a]++;
      }
      if (b != 1) {
        if (fact[b]) {
          f = true;
          return;
        }
        fact[b]++;
      }
    }
  }
}
int findGCD(int arr[], int n) {
  int result = arr[0];
  for (int i = 1; i < n; i++) {
    gcd(arr[i]);
    result = __gcd(arr[i], result);
  }
  return result;
}
void solve() {
  int n;
  cin >> n;
  int arr[n];

  for (int i = 0; i < n; i++)
    cin >> arr[i];

  int GCD = findGCD(arr, n);

  if (!f)
    cout << "pairwise coprime";
  else if (GCD == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";

  cout << endl;
}

int main() {
  int t;
  t = 1;
  while (t--) {

    solve();
  }
  return 0;
}

//       int anss[t+1];
//            anss[j]=ans;
//     for(int j=1;j<=t;j++) printf("Case %d: %d\\n",j,anss[j]);

Error: 0

Fixed submission:

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

int N;
int A[1000001];
bool walah = 1;
int x;

int solve1(int n) {
  if (n == N) {
    if (walah == 1) {
      return 1;
    } else {
      return 0;
    }
  } else {
    for (int i = n + 1; i <= N; i++) {
      if (__gcd(A[n], A[i]) != 1) {
        walah = 0;
      }
    }
    solve1(n + 1);
  }
}

int solve2(int n) {
  if (n == N + 1) {
    if (x == 1) {
      return 1;
    } else {
      return 0;
    }
  } else {
    x = __gcd(x, A[n]);
    solve2(n + 1);
  }
}

int main() {
  cin >> N;

  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  x = A[1];
  if (solve1(1) == 1) {
    cout << "pairwise coprime" << endl;
  } else if (solve2(2) == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

#define maxn 1000010
int notp[maxn];
int vis[maxn];
int prm[maxn], tot;
int ai[maxn];

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

void sieve(int n) {
  notp[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!notp[i])
      prm[++tot] = i;
    for (int j = 1; 1ll * prm[j] * i <= n && j <= tot; j++) {
      notp[i * prm[j]] = 1;
      if (i % prm[j] == 0)
        break;
    }
  }
}

inline int readin() {
  int x = 0, s = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      s = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * s;
}

int main() {
  int n, g;
  n = readin();
  sieve(1000001);
  for (int i = 1; i <= n; i++)
    ai[i] = readin();
  g = ai[1];
  for (int i = 2; i <= n; i++)
    g = gcd(g, ai[i]);
  if (g > 1) {
    puts("not coprime");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (!notp[ai[i]])
      vis[ai[i]]++;
    else {
      for (int j = 1; j <= 100 && prm[j] <= ai[i]; j++) {
        if (ai[i] % prm[j] == 0) {
          vis[prm[j]]++;
        }
        while (ai[i] % prm[j] == 0)
          ai[i] /= prm[j];
      }
      if (ai[i] > 1)
        vis[ai[i]]++;
    }
  }
  for (int i = 2; i <= 1000000; i++)
    if (vis[i] >= 2) {
      puts("setwise coprime");
      return 0;
    }
  puts("pairwise coprime");
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int arr1[1000050];
bool gcdback(int a, int b) { return (__gcd(a, b) == 1); }
bool coprimeall(int n) {
  int max1 = n;
  bool here = true;
  int pref[100000] = {0};
  for (int i = 0; i < n; i++) {
    int x = arr1[i];
    for (int j = 2; j * j <= x; j++) {
      if (x % j == 0) {
        pref[j]++;
        while (x % j == 0) {
          x /= j;
        }
      }
      if (pref[j] >= max1) {
        here = false;
      }
    }
    if (x != 1) {
      pref[x]++;
      if (pref[x] >= max1) {
        here = true;
      }
    }
  }
  return here;
}
int solveitabdo(int n) {
  int count1 = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (gcdback(arr1[i], arr1[j]) == 1) {
        count1++;
      } else
        return count1;
    }
  }
  return count1;
}
int main() {
  int n, counter = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr1[i]);
  }
  counter = solveitabdo(n);
  if (counter == n) {
    printf("pairwise coprime");
  } else if (coprimeall(n)) {
    printf("setwise coprime");
  } else {
    printf("not coprime");
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
vector<int> least_prime;
void leastPrimeFactor(int n) {
  // Create a vector to store least primes.
  // Initialize all entries as 0.
  least_prime.resize(n + 1, 0);

  // We need to print 1 for 1.
  least_prime[1] = 1;

  for (int i = 2; i <= n; i++) {
    // least_prime[i] == 0
    // means it i is prime
    if (least_prime[i] == 0) {
      // marking the prime number
      // as its own lpf
      least_prime[i] = i;

      // mark it as a divisor for all its
      // multiples if not already marked
      for (int j = 2 * i; j <= n; j += i)
        if (least_prime[j] == 0)
          least_prime[j] = i;
    }
  }

  // print least prime factor of
  // of numbers till n
  //    for (int i = 1; i <= n; i++)
  //        cout << "Least Prime factor of "
  //             << i << ": " << least_prime[i] << "\\n";
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  if (n == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  map<int, int> m;
  leastPrimeFactor(*max_element(a.begin(), a.end()) + 2);
  for (int i = 0; i < a.size(); i++) {
    unordered_map<int, int> ma;
    while (a[i] != 1) {
      if (!ma[least_prime[a[i]]]) {
        m[least_prime[a[i]]]++;
        ma[least_prime[a[i]]]++;
      }
      a[i] /= least_prime[a[i]];
    }
    ma.clear();
  }
  int flag = 0;
  for (auto it : m) {
    if (it.second > 1) {
      flag = 1;
      break;
    }
  }
  if (!flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = __gcd(b[0], b[1]);
  for (int i = 2; i < b.size(); i++)
    g = __gcd(g, b[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  if (n == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  map<int, int> m;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 2; a[i] > 1; j++) {
      if (a[i] % j == 0) {
        m[j]++;
        while (a[i] % j == 0)
          a[i] = a[i] / j;
      }
    }
  }
  int flag = 0;
  for (auto it : m) {
    if (it.second > 1) {
      flag = 1;
      break;
    }
  }
  if (!flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = __gcd(b[0], b[1]);
  for (int i = 2; i < b.size(); i++)
    g = __gcd(g, b[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

ll gcd(ll m, ll n) {
  ll tmp;
  while (m % n) {
    tmp = n;
    n = m % n;
    m = tmp;
  }
  return n;
}

pair<map<ll, ll>, set<ll>> prime_factor(ll n) {
  map<ll, ll> res;
  set<ll> primes;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0)
      primes.insert(i);

    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) {
    res[n] = 1;
    primes.insert(n);
  }
  return make_pair(res, primes);
}

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

  int n;
  cin >> n;

  vector<ll> a(n);
  ll g;
  bool ispair = true;
  map<ll, ll> primes;
  rep(i, n) {
    cin >> a[i];
    if (i == 0) {
      g = a[i];
    } else {
      g = gcd(g, a[i]);
    }
    if (a[i] == 1)
      continue;
    if (ispair) {
      set<ll> pri = prime_factor(a[i]).second;
      for (ll elem : pri) {
        if (primes[elem] > 0) {
          ispair = false;
          break;
        }
        ++primes[elem];
      }
    }
  }

  if (ispair)
    puts("pairwise coprime");
  else if (g == 1)
    puts("setwise coprime");
  else
    puts("not coprime");

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

ll gcd(ll m, ll n) {
  ll tmp;
  while (m % n) {
    tmp = n;
    n = m % n;
    m = tmp;
  }
  return n;
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) {
    res[n] = 1;
  }
  return res;
}

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

  int n;
  cin >> n;
  vector<ll> a(n);
  ll g;
  bool ispair = true;
  vector<int> e(100010, 0);
  rep(i, n) {
    cin >> a[i];
    if (i == 0) {
      g = a[i];
    } else {
      g = gcd(g, a[i]);
    }
    if (a[i] == 1)
      continue;
    if (ispair) {
      if (e[a[i]] > 0)
        ispair = false;
      else {
        map<ll, ll> pri = prime_factor(a[i]);

        for (auto key : pri) {
          ll base = key.first;
          if (e[base] > 0)
            continue;
          ll mul = 1;
          while (base * mul < 100000) {
            ++e[base * mul];
            ++mul;
          }
        }
      }
    }
  }

  if (ispair)
    puts("pairwise coprime");
  else if (g == 1)
    puts("setwise coprime");
  else
    puts("not coprime");

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

#include <algorithm>
#include <cstdio>

using namespace std;

const int MAXN = 1e6 + 3;
int N;
int A[MAXN];
bool visited[MAXN];
int appeared[MAXN];

int main() {
  int max_num = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    max_num = max(max_num, A[i]);
    appeared[A[i]]++;
  }

  bool has_cd = false, not_pair_wise = false;

  for (int i = 2; i <= max_num; i++) {
    if (visited[i])
      continue;
    int c = 0;
    for (int k = i; k <= max_num; k += i) {
      visited[k] = true;
      c += appeared[k];
    }

    if (c == N)
      has_cd = true;
    if (c > 1)
      not_pair_wise = true;
  }

  if (has_cd)
    puts("not coprime");
  else if (not_pair_wise)
    puts("setwise coprime");
  else
    puts("pairwise coprime");

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

const int MAXN = 1e6 + 3;
int N;
int A[MAXN];
bool visited[MAXN];

int main() {
  int max_num = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    max_num = max(max_num, A[i]);
  }

  bool has_cd = false, not_pair_wise = false;

  for (int i = 2; i <= max_num; i++) {
    if (visited[i])
      continue;
    for (int k = i; k <= max_num; k += i)
      visited[k] = true;
    int c = 0;
    for (int k = 0; k < N; k++)
      if (A[k] % i == 0)
        c++;
    if (c == N)
      has_cd = true;
    if (c > 1)
      not_pair_wise = true;
  }

  if (has_cd)
    puts("not coprime");
  else if (not_pair_wise)
    puts("setwise coprime");
  else
    puts("pairwise coprime");

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

#include <bits/stdc++.h>

#define endl '\\n'

using namespace std;
using ll = long long int;

vector<int> factors(1e6 + 10, 0);

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<int> values(n);
  int gcd = 0;
  for (auto &v : values) {
    cin >> v;
    gcd = __gcd(gcd, v);
  }

  for (int p = 0; p < n; p++) {
    int num = values[p];

    for (int i = 1; i * i <= num; i++) {
      if (num % i == 0) {
        factors[i]++;
        factors[num / i]++;

        if (i == num / i)
          factors[i]--;

        if (i != 1 and factors[i] > 1) {

          if (gcd == 1)
            puts("setwise coprime");
          else
            puts("not coprime");

          return 0;
        }

        if (num / i != 1 and factors[num / i] > 1) {

          if (gcd == 1)
            puts("setwise coprime");
          else
            puts("not coprime");

          return 0;
        }
      }
    }
  }

  puts("pairwise coprime");

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define endl '\\n'

using namespace std;
using ll = long long int;

vector<int> factors(1e6, 0);

int main() {

  int n;
  cin >> n;

  vector<int> values(n);
  for (auto &v : values)
    cin >> v;

  for (int p = 0; p < n; p++) {
    int num = values[p];

    for (int i = 1; i * i <= num; i++) {
      if (num % i == 0) {
        factors[i]++;
        factors[num / i]++;

        if (i == num / i)
          factors[i]--;
      }
    }
  }

  // for (int i=0; i<10; i++) cout << factors[i] << " ";
  // cout  << endl;

  for (int i = 2; i <= 1e6; i++) {
    if (factors[i] > 1) {

      int gcd = 0;

      for (int i = 0; i < n; i++) {
        gcd = __gcd(gcd, values[i]);
      }

      if (gcd == 1)
        puts("setwise coprime");
      else
        puts("not coprime");

      return 0;
    }
  }

  puts("pairwise coprime");

  return 0;
}