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

#include <bits/stdc++.h>

using namespace std;

#define ll long long

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; ++i)
    cin >> a[i];
  vector<ll> primes = {2, 3, 5, 7, 11, 13};
  for (ll i = 17; i < 100000; i += 2) {
    bool ok = true;
    for (ll j = 0; primes[j] * primes[j] <= i; ++j) {
      if (i % primes[j] == 0) {
        ok = false;
        break;
      }
    }
    if (ok)
      primes.emplace_back(i);
  }

  map<ll, ll> cnt;
  for (ll i : a) {
    ll t = i;
    for (ll j = 0; primes[j] * primes[j] <= t; ++j) {
      if (t % primes[j] == 0)
        cnt[primes[j]]++;
      while (t % primes[j] == 0)
        t /= primes[j];
    }
    if (t != 1)
      cnt[t]++;
  }

  ll hi = 0;
  for (auto p : cnt)
    hi = max(hi, p.second);
  if (hi <= 1) {
    printf("pairwise coprime");
    return 0;
  }

  printf(hi < n ? "setwise coprime" : "not coprime");

  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

template <typename T> void read(T &x) {
  x = 0;
  char c = getchar();
  T sig = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      sig = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  x *= sig;
}

class Solution {
public:
  void solve() {
    int n;
    read(n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
      read(a[i]);
    vector<int> primes = {2, 3, 5, 7, 11, 13};
    for (int i = 17; i < 1000; i += 2) {
      bool ok = true;
      for (int j = 0; primes[j] * primes[j] <= i; ++j) {
        if (i % primes[j] == 0) {
          ok = false;
          break;
        }
      }
      if (ok)
        primes.emplace_back(i);
    }
    map<int, int> cnt;
    for (int i : a) {
      int t = i;
      for (int j = 0; primes[j] * primes[j] <= t; ++j) {
        if (t % primes[j] == 0)
          cnt[primes[j]]++;
        while (t % primes[j] == 0)
          t /= primes[j];
      }
      if (t != 1)
        cnt[t]++;
    }
    int hi = 0;
    for (auto p : cnt)
      hi = max(hi, p.second);
    if (hi <= 1) {
      printf("pairwise coprime");
      return;
    }
    printf(hi < n ? "setwise coprime" : "not coprime");
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution solution = Solution();
  solution.solve();
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int prims[1000006];

int cnt;
int mm[1000006], yins[1000006];
void ssp(int n) {
  for (int i = 2; i <= n; i++) {
    if (mm[i] == 0)
      prims[cnt++] = i;

    for (int j = 0; prims[j] <= n / i; j++) {
      mm[prims[j] * i] = 1;
      if (i % prims[j] == 0)
        break;
    }
  }
}

int main() {
  ssp(3000);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < cnt; i++) {
      int tot = 0;
      while (t % prims[i] == 0) {
        t /= prims[i];
        tot = 1;
      }
      if (tot)
        yins[prims[i]]++;
    }
    if (t > 1)
      yins[t]++;
  }
  int st = 0;
  for (int i = 1; i < 1000005; i++) {
    if (yins[i] >= 2)
      st++;
    if (yins[i] == n) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  if (st == 0) {
    cout << "pairwise coprime" << endl;
  } else
    cout << "setwise coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;

#define optimize()                                                             \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define file()                                                                 \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define tt                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define nl cout << "\\n";
#define sp cout << " ";
#define rep(i, a, b) for (long long i = a; i < b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4 * atan(1);

int main() {
  optimize();

  int n;
  cin >> n;

  ll a[n];
  bool p = 1;

  cin >> a[0];
  ll g = a[0];

  for (int i = 1; i < n; i++) {
    cin >> a[i];
    g = __gcd(g, a[i]);
  }

  if (g > 1) {
    cout << "not coprime\\n";
    return 0;
  }

  for (int i = 0; i < n && p == 1; i++) {
    for (int j = i + 1; j < n && p == 1; j++) {
      if (__gcd(a[i], a[j]) > 1) {
        p = 0;
        break;
      }
    }
  }

  if (p == 1)
    cout << "pairwise coprime\\n";

  else
    cout << "setwise coprime\\n";

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

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

vector<int> D(1000001, -1);

void P() {
  D.at(0) = D.at(1) = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (D.at(i) != -1)
      continue;
    for (int j = 2; i * j <= 1000000; j++) {
      if (D.at(i * j) == -1)
        D.at(i * j) = i;
    }
  }
  return;
}

int main() {
  P();
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  int G = A.at(0);
  for (int i = 0; i < N; i++)
    G = __gcd(G, A.at(i));
  string ans = "pairwise coprime";
  set<int> S;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 1)
      continue;
    while (D.at(A.at(i)) > 0) {
      if (S.count(D.at(A.at(i)))) {
        ans = "setwise coprime";
        break;
      } else {
        int x = D.at(A.at(i));
        S.insert(x);
        while (A.at(i) % x == 0)
          A.at(i) /= x;
      }
    }
    if (A.at(i) != 1) {
      if (S.count(A.at(i))) {
        ans = "setwise coprime";
        break;
      } else
        S.insert(A.at(i));
    }
  }
  if (G != 1)
    ans = "not coprime";
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

vector<int> D(1000001, -1);

void P() {
  D.at(0) = D.at(1) = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (D.at(i) != -1)
      continue;
    for (int j = 2; i * j <= 1000000; j++) {
      if (D.at(i * j) == -1)
        D.at(i * j) = i;
    }
  }
  return;
}

int main() {
  P();
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  int G = A.at(0);
  for (int i = 0; i < N; i++)
    G = __gcd(G, A.at(i));
  string ans = "pairwise coprime";
  set<int> S;
  for (int i = 0; i < N; i++) {
    bool B = false;
    while (D.at(A.at(i)) != -1) {
      if (S.count(D.at(A.at(i)))) {
        ans = "setwise coprime";
        B = true;
        break;
      }
      S.insert(D.at(A.at(i)));
      A.at(i) /= D.at(A.at(i));
    }
    if (B)
      break;
  }
  if (G != 1)
    ans = "not coprime";
  cout << ans << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define M 1000000007
ll factor[1000005];
bool flag = false;
void fillDivisors(ll x) {

  if (flag == true)
    return;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      ll fact1 = i;
      ll fact2 = x / i;
      if (fact1 == fact2) {
        fact1 = i;
        fact2 = 1;
      }

      if (fact1 != 1) {
        if (factor[fact1]) {
          flag = true;
          return;
        }
        factor[fact1]++;
      }

      if (fact2 != 1) {
        if (factor[fact2]) {
          flag = true;
          return;
        }

        factor[fact2]++;
      }
    }
  }
}

int main() {

#ifndef ONLINE_JUDGE

  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

#endif

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

  ll gcd = a[0];
  fillDivisors(a[0]);
  for (int i = 1; i < n; ++i) {

    fillDivisors(a[i]);
    gcd = __gcd(gcd, a[i]);
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

#ifndef ONLINE_JUDGE

  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

#endif

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

  ll x = a[0];

  for (int i = 1; i < n; ++i) {
    x = __gcd(x, a[i]);
  }

  int flag = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; j++) {
      if (__gcd(a[i], a[j]) != 1) {
        flag = 1;
        break;
      }
    }
    if (flag)
      break;
  }
  if (flag) {
    if (x == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  } else
    cout << "pairwise coprime";

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

#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back((x))
#define line() cerr << "DEBUG @" << __LINE__ << endl;
#define debug(x)                                                               \\
  cerr << "DEBUG @" << __LINE__ << " -> " << #x << " = " << x << endl;
using namespace std;

vector<int> m[(int)1e6 + 1];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int &x : v)
    cin >> x;
  const int mx = 1e6;
  vector<int> divisors(mx + 1);
  for (int i = 2; i <= 1000000; i++) {
    if (!divisors[i]) {
      for (int j = i; j <= 1000000; j += i) {
        divisors[j] = i;
      }
    }
  }
  bool pair_wise_coprime = true;
  bool gcd_is_one = true;

  for (int x : v) {
    int cur = x;
    unordered_set<int> q;
    while (cur != 1) {
      q.insert(divisors[cur]);
      cur /= divisors[cur];
    }
    for (int div : q) {
      auto &curr_map = m[div];
      curr_map.push_back(x);
      if (curr_map.size() > 1)
        pair_wise_coprime = false;
      if (curr_map.size() == n)
        gcd_is_one = false;
    }
  }
  if (pair_wise_coprime) {
    cout << "pairwise coprime\\n";
    return 0;
  }
  if (gcd_is_one) {
    cout << "setwise coprime\\n";
    return 0;
  }
  cout << "not coprime\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back((x))
#define line() cerr << "DEBUG @" << __LINE__ << endl;
#define debug(x)                                                               \\
  cerr << "DEBUG @" << __LINE__ << " -> " << #x << " = " << x << endl;
using namespace std;

const int MAX = 1e6;
int v[MAX], divisors[MAX + 1], x, cur, i, j, n;
vector<int> m[MAX];

int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &v[i]);
  for (i = 2; (i * i) <= MAX; i++) {
    if (!divisors[i]) {
      for (j = i; j <= MAX; j += i) {
        divisors[j] = i;
      }
    }
  }
  bool pair_wise_coprime = true;
  bool gcd_is_one = true;
  unordered_set<int> q;
  for (i = 0; i < n; i++) {
    x = v[i];
    cur = x;
    q.clear();
    while (cur != 1) {
      q.insert(divisors[cur]);
      cur /= divisors[cur];
    }
    for (int div : q) {
      auto &curr_map = m[div];
      curr_map.push_back(x);
      if (curr_map.size() > 1)
        pair_wise_coprime = false;
      if (curr_map.size() == n)
        gcd_is_one = false;
    }
  }
  if (pair_wise_coprime) {
    puts("pairwise coprime");
    return 0;
  }
  if (gcd_is_one) {
    puts("setwise coprime");
    return 0;
  }
  puts("not coprime");
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair<ll, ll>
#define nl "\\n"
const int L = 1000006;
ll spf[L + 10];
map<ll, ll> x;
void soe() {
  ll i, j;
  for (i = 1; i <= L; i++)
    spf[i] = i;
  for (i = 2; i * i <= L; i++) {
    if (spf[i] == i) {
      for (j = i * i; j <= L; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}
vector<ll> factorise(ll x) {
  vector<ll> v;
  while (x != 1) {
    v.pb(spf[x]);
    x = x / spf[x];
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  ll n, i;
  soe();
  cin >> n;
  ll a[n + 2];
  for (i = 0; i < n; i++)
    cin >> a[i];
  ll gcd = a[0];
  for (i = 1; i < n; i++)
    gcd = __gcd(gcd, a[i]);
  // for(i=1;i<L;i++)
  // {
  // 	factorise(i);
  // }
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    for (auto y : sub) {
      x[y]++;
    }
  }
  ll ff = 0;
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    map<ll, ll> subb;
    for (auto it : sub)
      subb[it]++;
    ll f = 0;
    for (auto y : subb) {
      ll p = x[y.ff] - y.ss;
      if (p != 0) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      ff = 1;
      break;
    }
  }
  if (ff == 0)
    cout << "pairwise coprime";
  else if (gcd == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  cout << nl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair<ll, ll>
#define nl "\\n"
const int L = 1000006;
ll spf[L + 10];
map<ll, ll> x;
ll soe() {
  ll i, j;
  for (i = 1; i <= L; i++)
    spf[i] = i;
  for (i = 2; i * i <= L; i++) {
    if (spf[i] == i) {
      for (j = i * i; j <= L; j += i) {
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
}
vector<ll> factorise(ll x) {
  vector<ll> v;
  while (x != 1) {
    v.pb(spf[x]);
    x = x / spf[x];
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  ll n, i;
  soe();
  cin >> n;
  ll a[n + 2];
  for (i = 0; i < n; i++)
    cin >> a[i];
  ll gcd = a[0];
  for (i = 1; i < n; i++)
    gcd = __gcd(gcd, a[i]);
  // for(i=1;i<L;i++)
  // {
  // 	factorise(i);
  // }
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    for (auto y : sub) {
      x[y]++;
    }
  }
  ll ff = 0;
  for (i = 0; i < n; i++) {
    vector<ll> sub = factorise(a[i]);
    map<ll, ll> subb;
    for (auto it : sub)
      subb[it]++;
    ll f = 0;
    for (auto y : subb) {
      ll p = x[y.ff] - y.ss;
      if (p != 0) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      ff = 1;
      break;
    }
  }
  if (ff == 0)
    cout << "pairwise coprime";
  else if (gcd == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  cout << nl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
// int a[100010],n,j;
bool ok = false;
int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
void factor(int x, long long fact[]) {
  if (ok == 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]) {
          ok = true;
          return;
        }
        fact[a]++;
      }
      if (b != 1) {
        if (fact[b]) {
          ok = true;
          return;
        }
        fact[b]++;
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  int a[n];
  // cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int totalgcd = a[0];
  long long fact[1000001] = {0};
  // factor(a[0],fact);
  for (int i = 1; i < n; i++) {
    totalgcd = __gcd(totalgcd, a[i]);
    // factor(a[i],fact);
  }
  // fact[1]=1;
  for (int i = 0; i < n; i++)
    factor(a[i], fact);

  // int ispairwise=1;
  //  for(int i=0;i<n;i++)
  //  {
  //    if(fact[a[i]]>1){ispairwise=0;break;}
  //  }
  if (!ok) {
    cout << "pairwise coprime" << endl;
  } else if (totalgcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
// int a[100010],n,j;
bool ok = true;
int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
void factor(int number, long long fact[]) {
  for (long long i = 2; (long long)i * i <= number; i++) {
    if (number % i == 0) {
      if (i != (number / i)) {
        if (fact[i] || fact[number / i]) {
          ok = false;
          return;
        }
        fact[i]++;
        fact[number / i]++;
      } else {
        if (fact[i]) {
          ok = false;
          return;
        }
        fact[i]++;
      }
    }
  }
  fact[number]++;
}
int main() {
  int n;
  cin >> n;
  int a[n];
  // cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int totalgcd = a[0];
  long long fact[100001] = {0};
  // factor(a[0],fact);
  for (int i = 1; i < n; i++) {
    totalgcd = __gcd(totalgcd, a[i]);
    // factor(a[i],fact);
  }
  for (int i = 0; i < n; i++)
    factor(a[i], fact);
  fact[1] = 1;
  // int ispairwise=1;
  //  for(int i=0;i<n;i++)
  //  {
  //    if(fact[a[i]]>1){ispairwise=0;break;}
  //  }
  if (ok) {
    cout << "pairwise coprime" << endl;
  } else if (totalgcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define io                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 1000005;
const int mod = 1e9 + 7;
int main() {
  io;
  int n, a[N];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int x = a[0];
  for (int i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (mp[j]) {
          cout << "setwise coprime";
          return 0;
        }
        mp[j]++;
        while (a[i] % j == 0)
          a[i] /= j;
      }
    }
    if (a[i] != 1) {
      if (mp[a[i]]) {
        cout << "setwise coprime";
        return 0;
      }
      mp[a[i]]++;
    }
  }
  cout << "pairwise coprime";
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define io                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 200005;
const int mod = 1e9 + 7;
int main() {
  io;
  int n, a[N];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int x = a[0];
  for (int i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x != 1) {
    cout << "not coprime" << endl;
    return 0;
  }
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (mp[j]) {
          cout << "setwise coprime";
          return 0;
        }
        mp[j]++;
        while (a[i] % j == 0)
          a[i] /= j;
      }
    }
    if (a[i] != 1) {
      if (mp[a[i]]) {
        cout << "setwise coprime";
        return 0;
      }
      mp[a[i]]++;
    }
  }
  cout << "pairwise coprime";
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

const int mod = (int)(1e9) + 7;
using ll = long long;

vector<int> v(1000005);

int cnt[1000005];

int main() {
  vector<int> primes;
  for (int i = 2; i <= 1005; i++) {
    int sq = sqrt(i);
    int f = 0;
    for (int j = 2; j <= sq; j++) {
      if (i % j == 0)
        f = 1;
    }
    if (!f)
      primes.push_back(i);
  }

  memset(cnt, 0, sizeof(cnt));

  int n;
  scanf("%d", &n);
  bool pairwise = true;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    int sq = sqrt(v[i]);
    int t = v[i];
    for (int j = 0; j < primes.size(); j++) {
      if (v[i] % primes[j] == 0) {
        if (cnt[primes[j]])
          pairwise = false;
        cnt[primes[j]]++;
        while (t % primes[j] == 0)
          t /= primes[j];
      }
    }
    if (cnt[t])
      pairwise = false;
    if (t > 1)
      cnt[t]++;
  }
  if (pairwise) {
    puts("pairwise coprime");
    return 0;
  }

  int g = v[0];
  for (int i = 1; i < n; i++) {
    g = __gcd(g, v[i]);
  }
  if (g == 1) {
    puts("setwise coprime");
    return 0;
  }
  puts("not coprime");
}


Error: 0

Fixed submission:

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

const int mod = (int)(1e9) + 7;
using ll = long long;

int main() {
  vector<int> primes;
  for (int i = 2; i <= 1005; i++) {
    int sq = sqrt(i);
    int f = 0;
    for (int j = 2; j <= sq; j++) {
      if (i % j == 0)
        f = 1;
    }
    if (!f)
      primes.push_back(i);
  }

  int cnt[100000];
  memset(cnt, 0, sizeof(cnt));

  int n;
  scanf("%d", &n);
  vector<int> v(1000005);
  bool pairwise = true;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    int sq = sqrt(v[i]);
    for (int j = 0; primes[j] <= sq; j++) {
      if (v[i] % primes[j] == 0) {
        if (cnt[primes[j]])
          pairwise = false;
        cnt[primes[j]]++;
      }
    }
  }
  if (pairwise) {
    puts("pairwise coprime");
    return 0;
  }

  int g = v[0];
  for (int i = 1; i < n; i++) {
    g = __gcd(g, v[i]);
  }
  if (g == 1) {
    puts("setwise coprime");
    return 0;
  }
  puts("not coprime");
}