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

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

int lpfact[1000005];

void seive() {
  lpfact[0] = lpfact[1] = 1;
  for (int i = 2; i <= 1000000; i += 2) {
    lpfact[i] = 2;
  }
  for (int i = 3; i <= 1000000; i += 2) {
    if (!lpfact[i]) {
      for (int j = 1; i * j <= 1000000; j++) {
        if (!lpfact[i * j]) {
          lpfact[i * j] = i;
        }
      }
    }
  }
}

int main() {
  int t = 1;
  seive();
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n), vis(1000001, 0);
    vector<set<int>> pfs(n);
    bool ispairwise = 1;
    bool coprime = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      int x = a[i];
      if (x == 0)
        coprime = 1;
      while (x > 1) {
        pfs[i].insert(lpfact[x]);
        x /= lpfact[x];
      }
      for (int y : pfs[i]) {
        if (vis[y]) {
          ispairwise = 0;
        }
        vis[y] = 1;
      }
    }
    set<int> intersection;

    for (int x : pfs[0]) {
      intersection.insert(x);
    }

    for (int i = 1; i < n; i++) {
      set<int> newIntersection;
      for (int x : pfs[i]) {
        if (intersection.find(x) != intersection.end())
          newIntersection.insert(x);
      }
      intersection = newIntersection;
    }

    if (ispairwise) {
      cout << "pairwise coprime" << endl;
    } else {
      if (intersection.size() != 0 && coprime == 0) {
        cout << "not coprime" << endl;
      } else {
        cout << "setwise coprime" << endl;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int lpfact[1000005];

void seive() {
  for (int i = 2; i <= 1000000; i += 2) {
    lpfact[i] = 2;
  }
  for (int i = 3; i <= 1000000; i += 2) {
    if (!lpfact[i]) {
      for (int j = 1; i * j <= 1000000; j++) {
        if (!lpfact[i * j]) {
          lpfact[i * j] = i;
        }
      }
    }
  }
  // for(int i=0; i<50; i++)
  //     cout<<lpfact[i]<<" ";
  // cout<<endl;
}

int main() {
  int t = 1;
  seive();
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n), vis(n + 1, 0);
    vector<set<int>> pfs(n);
    bool ispairwise = 1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      int x = a[i];
      while (x > 1) {
        pfs[i].insert(lpfact[x]);
        x /= lpfact[x];
      }
      for (int y : pfs[i]) {
        if (vis[y]) {
          ispairwise = 0;
          vis[y] = 1;
          break;
        }
        vis[y] = 1;
      }
    }
    set<int> intersection;
    for (int i = 0; i < n; i++) {
      if (intersection.empty()) {
        for (int x : pfs[i]) {
          intersection.insert(x);
        }
      } else {
        set<int> newIntersection;
        for (int x : pfs[i]) {
          if (intersection.find(x) != intersection.end())
            newIntersection.insert(x);
        }
        intersection = newIntersection;
      }
    }

    if (ispairwise) {
      cout << "pairwise coprime" << endl;
    } else {
      if (intersection.size() != 0) {
        cout << "not coprime" << endl;
      } else {
        cout << "setwise coprime" << endl;
      }
    }
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long int
using namespace std;
map<int, int> mp;
bool trug = false;

void prime_factor(int val) {
  int cnt = 0;
  while (val % 2 == 0) {
    cnt++;
    if (cnt == 1)
      mp[2]++;
    if (mp[2] > 1) {
      trug = true;
    }
    val /= 2;
  }
  for (int i = 3; i <= sqrt(val); i += 2) {

    cnt = 0;
    while (val % i == 0) {
      cnt++;
      if (cnt == 1)
        mp[i]++;
      if (mp[i] > 1) {
        trug = true;
      }
      val /= i;
    }
  }
  if (val > 2) {
    mp[val]++;
    if (mp[val] > 1) {
      trug = true;
    }
  }
}

bool co_prime(int arra[], int n) {
  bool flag = true;
  for (int i = 0; i < n; i++) {
    prime_factor(arra[i]);
    if (trug == true) {
      flag = false;
      break;
    }
  }

  if (flag == true)
    return true;
  else
    return false;
}
bool setwise_prime(int arra[], int n) {
  int result = arra[0];
  for (int i = 1; i < n; i++) {
    result = __gcd(result, arra[i]);
    if (result == 1)
      break;
  }
  if (result == 1)
    return true;
  else
    return false;
}
signed main() {
  int n;
  cin >> n;
  int arra[n + 5];
  for (int i = 0; i < n; i++) {
    cin >> arra[i];
  }
  if (co_prime(arra, n) == true)
    cout << "pairwise coprime" << endl;
  else if (setwise_prime(arra, n) == true)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long int
using namespace std;
vector<int> vec;

void prime_factor(int val) {
  int cnt = 0;
  while (val % 2 == 0) {
    cnt++;
    if (cnt == 1)
      vec.push_back(2);
    val /= 2;
  }
  for (int i = 3; i * i <= val; i += 2) {
    int val2 = val;
    cnt = 0;
    while (val2 % i == 0) {
      cnt++;
      if (cnt == 1)
        vec.push_back(i);
      val2 /= i;
    }
  }
}

bool co_prime(int arra[], int n) {
  for (int i = 0; i < n; i++) {
    prime_factor(arra[i]);
  }
  sort(vec.begin(), vec.end());
  bool flag = true;
  for (int i = 0; i < vec.size() - 1; i++) {
    if (vec[i] == vec[i + 1]) {
      flag = false;
      break;
    }
  }
  if (flag == true)
    return true;
  else
    return false;
}
bool setwise_prime(int arra[], int n) {
  int result = arra[0];
  for (int i = 1; i < n; i++) {
    result = __gcd(result, arra[i]);
    if (result == 1)
      break;
  }
  if (result == 1)
    return true;
  else
    return false;
}
signed main() {
  int n;
  cin >> n;
  int arra[n + 5];
  for (int i = 0; i < n; i++)
    cin >> arra[i];
  if (co_prime(arra, n) == true)
    cout << "pairwise coprime" << endl;
  else if (setwise_prime(arra, n) == true)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<int> prime[1000001];

signed main() {
  for (int i = 2; i < 1000001; i++) {
    if (prime[i].size())
      continue;
    for (int j = i; j < 1000001; j += i)
      prime[j].push_back(i);
  }

  int n;
  cin >> n;
  set<int> s;
  int tmp = 0, pa = 0;
  while (n--) {
    int a;
    cin >> a;
    tmp = __gcd(tmp, a);
    for (int p : prime[a]) {
      if (s.count(p))
        pa = 1;
      s.insert(p);
    }
  }
  if (!pa)
    cout << "pairwise coprime" << endl;
  else if (tmp == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: TLE

Fixed submission:

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

int prime[1000001];
vector<int> P;
template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}

signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());

  for (int i = 2; i < 1000001; i++)
    prime[i] = 1;
  for (long i = 2; i < 1000001; i++) {
    if (prime[i]) {
      P.push_back(i);
      for (long j = i * i; j < 1000001; j += i)
        prime[j] = 0;
    }
  }

  int N = P.size();
  vector<int> used(N, 0);

  bool pa = 1;
  for (int a : v)
    for (int i = 0; i < N && P[i] <= a; i++)
      if (!(a % P[i]) && used[i]++)
        pa = 0;
  if (pa)
    fin("pairwise coprime");

  int tmp = v[0];
  for (int a : v)
    tmp = __gcd(tmp, a);
  if (tmp == 1)
    fin("setwise coprime");

  fin("not coprime");
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#define mm(a, x) memset(a, x, sizeof(a))
#define sync                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0)
#define ll long long
using namespace std;
const int N = 1e6 + 10;
int n, tot;
int a[N];
int prime[N], vis[N], cnt[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void Euler() {
  vis[1] = 1;
  for (int i = 2; i < N; ++i) {
    if (vis[i] == 0)
      prime[++tot] = i;
    for (int j = 1; j <= tot && i * prime[j] < N; ++j) {
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
int main(void) {
  sync;
  cin >> n;
  Euler();
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  bool f1 = true;
  int g = a[0];
  for (int i = 0; i < n; ++i) {
    g = gcd(g, a[i]);
    int aa = a[i];
    for (int j = 1; j <= tot; ++j) {
      if (!vis[aa]) {
        if (cnt[aa])
          f1 = false;
        ++cnt[aa];
        break;
      }
      if (aa % prime[j] == 0) {
        if (cnt[prime[j]])
          f1 = false;
        ++cnt[prime[j]];
        while (aa % prime[j] == 0) {
          aa /= prime[j];
        }
      }
      if (aa == 1)
        break;
    }
  }
  if (f1)
    cout << "pairwise coprime" << endl;
  else {
    if (g == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#define mm(a, x) memset(a, x, sizeof(a))
#define sync                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0)
#define ll long long
using namespace std;
const int N = 1e6 + 10;
int n, tot;
int a[N];
int prime[N], vis[N], cnt[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void Euler() {
  vis[1] = 1;
  for (int i = 2; i < N; ++i) {
    if (vis[i] == 0)
      prime[++tot] = i;
    for (int j = 1; j <= tot && i * prime[j] < N; ++j) {
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}
int main(void) {
  sync;
  cin >> n;
  Euler();
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  bool f1 = true;
  int g = a[0];
  for (int i = 0; i < n; ++i) {
    g = gcd(g, a[i]);
    for (int j = 1; j <= tot; ++j) {
      if (a[i] % prime[j] == 0) {
        if (cnt[j])
          f1 = false;
        while (a[i] % prime[j] == 0) {
          a[i] /= prime[j];
          ++cnt[j];
        }
      }
      if (a[i] == 1)
        break;
    }
  }
  if (f1)
    cout << "pairwise coprime" << endl;
  else {
    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;
const int maxn = 1e6 + 10;
int n;
int a[maxn];
int c[maxn];
inline int R_Int() {
  int ch, a;
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = a * 10 + (ch ^ 48);
  return a;
}

inline int Gcd(int a, int b) { return b ? Gcd(b, a % b) : a; }
bool usd[maxn];
inline bool Sieve() {
  for (int i = 2; i <= 1e6; i++)
    if (!usd[i]) {
      int cnt = 0;
      for (int j = 1; i * j <= 1e6; j++) {
        int tmp = i * j;
        usd[tmp] = 1, cnt += c[tmp];
        if (cnt > 1)
          return 0;
      }
    }
  return 1;
}

int main() {
  n = R_Int();
  int G;
  for (int i = 1; i <= n; i++) {
    c[a[i] = R_Int()]++;
    G = (i == 1) ? a[i] : Gcd(G, a[i]);
  }
  if (Sieve()) {
    printf("pairwise coprime\\n");
    return 0;
  }
  if (G == 1)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
  return 0;
}


Error: TLE

Fixed submission:

// https://vjudge.net/contest/394236#problem/E
#include <algorithm>
#include <assert.h>
#include <bits/stdc++.h>
#include <chrono>
#include <climits>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;

/*
        time complexty
auto start = chrono::steady_clock::now();
    ............

auto endd = chrono::steady_clock::now();
auto dif =   endd- start;
cout << chrono::duration<double, milli>(dif).count() <<"ms"<<endl;

*/

int x, n, f1 = 1, f2 = 1;
map<int, int> mp;
int main() {

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {

    scanf("%d", &x);
    if (x != 1)
      mp[x]++;

    if (mp[x] > 1)
      f1 = 0;
    if (mp[x] >= n) {
      f2 = 0;
      break;
    }

    for (LL j = 2; j * j <= x; j++)

      if (x % j == 0) {

        mp[j]++;
        if ((x / j) != j)
          mp[x / j]++;

        if (mp[j] > 1 || mp[x / j] > 1)
          f1 = 0;
        if (mp[j] >= n || mp[x / j] >= n) {
          f2 = 0;
          break;
        }
      }
  }

  if (f1 || f2)
    puts(f1 ? "pairwise coprime\\n" : "setwise coprime\\n");

  else
    puts("not coprime\\n");

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

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

int main() {
  ll prime[maxS];
  memset(prime, -1, sizeof(prime));

  for (ll i = 2; i * i <= maxS; i++) {
    if (prime[i] == -1) {
      for (ll j = 2 * i; j < maxS; j += i) {
        prime[j] = i;
      }
    }
  }

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

  map<ll, ll> m;
  ll allGcd = a[0], flag = 0;

  for (int i = 0; i < n; i++) {
    ll temp = a[i];
    while (temp != 1) {
      ll no;
      if (prime[temp] == -1) {
        no = temp;
      } else {
        no = prime[temp];
      }
      if (m.find(no) != m.end()) {
        flag = 1;
        break;
      }
      // cout<<temp<<" "<<no<<" ";
      m[no]++;
      while (temp % no == 0) {
        temp /= no;
      }
    }
    if (flag == 1) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    allGcd = __gcd(allGcd, a[i]);
  }
  if (flag) {
    if (allGcd == 1) {
      cout << "setwise coprime\\n";
    } else {
      cout << "not coprime\\n";
    }
  } else {
    cout << "pairwise coprime\\n";
  }
}


Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

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

int main() {
  ll prime[maxS];
  memset(prime, -1, sizeof(prime));
  for (ll i = 2; i * i <= maxS; i++) {
    if (prime[i] == -1) {
      for (ll j = 2 * i; j <= maxS; j += i) {
        prime[j] = i;
      }
    }
  }
  // cout<<prime[200000]<<endl;
  // for(int i = 1; i < 22; i++){
  //     cout<<prime[i]<<" ";
  // }
  // cout<<endl;
  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> m;
  ll allGcd, flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (flag == 1) {
      continue;
    }
    ll temp = a[i];
    while (temp != -1) {
      ll no;
      if (prime[temp] == -1) {
        no = temp;
        temp = -1;
      } else {
        no = prime[temp];
        temp = temp / prime[temp];
      }
      if (m.find(no) != m.end()) {
        flag = 1;
        break;
      }
      // cout<<temp<<" "<<no<<" ";
      m[no]++;
      if (temp == -1) {
        // cout<<endl;
        break;
      }
      while (temp % no == 0) {
        temp /= no;
      }
      // cout<<temp<<" "<<no<<endl;
    }
  }
  allGcd = a[0];
  for (int i = 0; i < n; i++) {
    allGcd = __gcd(allGcd, a[i]);
  }
  if (flag) {
    if (allGcd == 1) {
      cout << "setwise coprime\\n";
    } else {
      cout << "not coprime\\n";
    }
  } else {
    cout << "pairwise coprime\\n";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// 素因数分解(関数ver)
map<int64_t, int64_t> prime_fact(int64_t n) {
  int64_t a = 2;
  map<int64_t, int64_t> mp;
  while (n >= a * a) {
    if (n % a == 0) {
      mp[a]++;
      n /= a;
    } else {
      a++;
    }
  }
  if (n != 1) {
    mp[n]++;
  }
  return mp;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  map<int, int> ans;
  for (int i = 0; i < N; i++) {
    map<int, int> A;
    int a = 2;
    int n = vec[i];
    while (n >= a * a) {
      if (n % a == 0) {
        A[a]++;
        n /= a;
      } else {
        a++;
      }
    }
    if (n != 1) {
      A[n]++;
    }
    for (auto itr = A.begin(); itr != A.end(); itr++) {
      ans[itr->first]++;
    }
  }

  int coprime = 0;

  for (auto itr = ans.begin(); itr != ans.end(); itr++) {
    coprime = max(coprime, itr->second);
  }

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


Error: TLE

Fixed submission:

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

// 素因数分解(関数ver)
map<int64_t, int64_t> prime_fact(int64_t n) {
  int64_t a = 2;
  map<int64_t, int64_t> mp;
  while (n >= a * a) {
    if (n % a == 0) {
      mp[a]++;
      n /= a;
    } else {
      a++;
    }
  }
  if (n != 1) {
    mp[n]++;
  }
  return mp;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  int coprime = 0;

  map<int, int> ans;
  for (int i = 0; i < N; i++) {
    map<int64_t, int64_t> A = prime_fact(vec[i]);
    for (auto itr = A.begin(); itr != A.end(); itr++) {
      ans[itr->first]++;
      coprime = max(coprime, ans[itr->first]);
    }
  }

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

// you should probably see at the bottom ..
#include <bits/stdc++.h>

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(), v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(1e6 + 10)
#define ff first
#define ss second

using namespace std;

vector<int> noCnt(N), prCnt(N);

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    noCnt[a]++;
  }
  int hasOne = 0, hasAll = 0;
  int got = 0;

  bitset<N> b;
  for (int i = 2; i < N; i++) {
    if (!b[i]) {
      for (int j = i; j < N; j += i) {
        if (noCnt[j])
          prCnt[i] += noCnt[j];
        b[j] = true;
      }
    }

    if (prCnt[i]) {
      got++;
      if (prCnt[i] == 1)
        hasOne++;
      if (prCnt[i] == n)
        hasAll++;
    }
  }

  if (hasOne == got)
    cout << "pairwise coprime" << endl;
  else if (!hasAll)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
  int t_c = 1;
  //    cin >> t_c;
  while (t_c--)
    solve();
}

/*
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
 */


Error: TLE

Fixed submission:

// you should probably see at the bottom ..
#include <bits/stdc++.h>

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(), v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(1e6 + 10)
#define ff first
#define ss second

using namespace std;
map<int, int> noCnt, prCnt;

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    noCnt[a]++;
  }

  bitset<N> b;
  for (int i = 2; i < N; i++) {
    if (!b[i]) {
      for (int j = i; j < N; j += i) {
        if (noCnt.count(j))
          prCnt[i] += noCnt[j];
        b[j] = true;
      }
    }
  }

  int hasOne = 0, hasAll = 0;
  int got = prCnt.size();
  for (auto it : prCnt) {
    if (it.ss == 1)
      hasOne++;
    if (it.ss == n)
      hasAll++;
  }

  if (hasOne == got)
    cout << "pairwise coprime" << endl;
  else if (!hasAll)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
  int t_c = 1;
  //    cin >> t_c;
  while (t_c--)
    solve();
}

/*
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
 */
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define nl '\\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;
  int gcd = 0, maxA = 0;
  vector<int> cnts(1e6 + 5);
  for (int i = 0, e; i < N; i++) {
    cin >> e;
    if (!gcd)
      gcd = e;
    gcd = __gcd(gcd, e);
    maxA = max(maxA, e);
    cnts[e]++;
  }

  bool flag = true;
  for (int i = 2; i <= maxA; i++) {
    int cnt = 0;
    for (int p = i; p <= maxA; p += i) {
      cnt += cnts[p];
    }
    if (cnt > 1) {
      flag = false;
    }
  }

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

  if (gcd == 1) {
    cout << "setwise coprime";
    return;
  }
  cout << "not coprime";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  // cout << nl;
  // }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define nl '\\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;
  int gcd = 0, maxA = 0;
  multiset<int> A;
  for (int i = 0, e; i < N; i++) {
    cin >> e;
    if (!gcd)
      gcd = e;
    gcd = __gcd(gcd, e);
    maxA = max(maxA, e);
    A.insert(e);
  }

  bool flag = true;
  for (int i = 2; i <= maxA; i++) {
    int cnt = 0;
    for (int p = i; p <= maxA; p += i) {
      cnt += A.count(p);
    }
    if (cnt > 1) {
      flag = false;
    }
  }

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

  if (gcd == 1) {
    cout << "setwise coprime";
    return;
  }
  cout << "not coprime";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  // cout << nl;
  // }

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

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int MAX = 1e5 + 7;

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

int primes[1000005];

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

  int n;
  cin >> n;
  vi v(n);
  FOR(i, n) cin >> v[i];

  int g = v[0];
  FOR(i, n) {
    int aux = v[i];
    for (int j = 2; j * j <= aux; j++) {
      if (aux % j == 0) {
        primes[j]++;
        while (aux % j == 0)
          aux /= j;
      }
    }
    if (aux > 1)
      primes[aux]++;
    g = gcd(g, v[i]);
  }

  bool pairwise = true;
  FOR(i, 1000005) {
    if (primes[i] > 1)
      pairwise = false;
  }

  if (pairwise)
    cout << "pairwise coprime\\n";
  else if (g == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int MAX = 1e5 + 7;

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

int primes[100005];

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

  int n;
  cin >> n;
  vi v(n);
  FOR(i, n) cin >> v[i];

  int g = v[0];
  FOR(i, n) {
    int aux = v[i];
    for (int j = 2; j * j <= aux; j++) {
      if (aux % j == 0) {
        primes[j]++;
        while (aux % j == 0)
          aux /= j;
      }
    }
    if (aux > 1)
      primes[aux]++;
    g = gcd(g, v[i]);
  }

  bool pairwise = true;
  FOR(i, 100005) {
    if (primes[i] > 1)
      pairwise = false;
  }

  if (pairwise)
    cout << "pairwise coprime\\n";
  else if (g == 1)
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";

  return 0;
}