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

#include <bits/stdc++.h>
using namespace std;
/*
    By: Umang Srivastava
*/
#define lli long long int
#define ld long double
#define mod 1000000007
#define lp(var, start, end, inc) for (var = start; var < end; var = var + inc)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<lli>
#define pll pair<lli, lli>
#define vpll vector<plli>
#define max(a, b) a > b ? a : b
#define min(a, b) a < b ? a : b

// lli findgcd(lli a, lli b, lli *x , lli *y)
// {
//     if(a==0)
//     {
//         *x=0,*y=1;
//         return b;
//     }
//     lli x1,y1;
//     lli gcd = findgcd(b%a,a,&x1,&y1);
//     *x=y1-(b/a)*x1;
//     *y=x1;
//     return gcd;
// }

// lli modInv(lli b)
// {
//     lli x,y;
//     lli g = findgcd(b,mod,&x,&y);
//     if(g!=1)
//         return -1;
//     return (x%mod + mod)%mod;
// }

lli gcd(lli a, lli b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  lli n, i, j;
  cin >> n;
  lli ar[n];
  lli prime[1000001] = {0};
  lli maxval = -1;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    prime[ar[i]]++;
    maxval = max(maxval, ar[i]);
  }
  lli c = 0;
  for (i = 2; i <= maxval; i++) {
    c = 0;
    for (j = i; j <= maxval; j += i) {
      c += prime[j];
      if (c > 1)
        break;
    }
    if (c > 1) {
      break;
    }
  }
  if (c < 2) {
    cout << "pairwise coprime";
    return 0;
  }
  lli result = ar[0];
  for (i = 1; i < n; i++) {
    result = gcd(result, ar[i]);
  }
  if (result == 1) {
    cout << "setwise coprime";
  } else
    cout << "not coprime";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/*
    By: Umang Srivastava
*/
#define lli long long int
#define ld long double
#define mod 1000000007
#define lp(var, start, end, inc) for (var = start; var < end; var = var + inc)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<lli>
#define pll pair<lli, lli>
#define vpll vector<plli>
#define max(a, b) a > b ? a : b
#define min(a, b) a < b ? a : b

lli gcd(lli a, lli b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  lli n, i, j, s = 0;
  cin >> n;
  lli ar[n];
  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }
  int f = 0;
  lli result = ar[0];
  for (i = 1; i < n; i++) {
    result = gcd(ar[i], result);
    if (result == 1)
      break;
  }
  if (result == 1) {
    f = 1;
  } else {
    cout << "not coprime";
    return 0;
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (gcd(ar[i], ar[j]) != 1) {
        f = 0;
        break;
      }
    }
    if (f == 0)
      break;
  }
  if (f == 1) {
    cout << "pairwise coprime";
  } else
    cout << "setwise coprime";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;

const int sz = 1e6 + 1;
bool sieve[sz], f;
int cnt[sz], num[sz];

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

void func(int n) {
  int d = 2, pre = 0;
  while (sieve[n]) {
    if (n % d == 0) {
      n /= d;
      if (pre != d) {
        if (++cnt[d] > 1)
          f = true;
        pre = d;
      }
    } else
      d++;
  }

  if (n != 1) {
    if (pre != n) {
      if (++cnt[n] > 1)
        f = true;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;

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

  for (int i = 0; i < N; i++) {
    cin >> num[i];
    func(num[i]);
  }

  if (!f)
    cout << "pairwise coprime";
  else {
    int g = num[0];
    for (int i = 1; i < N; i++)
      g = gcd(g, num[i]);
    if (g == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

const int sz = 1e6 + 1;
int cnt[sz], num[sz];

int gcd(int a, int b) {
  while (b) {
    int t = a;
    a = b;
    b = t % b;
  }
  return a;
}

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  bool f = false;
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> num[i];
    int t = num[i], d = 2;

    while (t != 1 && !f) {
      if (t % d == 0) {
        if (++cnt[d] > 1)
          f = true;
        while (t % d == 0)
          t /= d;
      }
      d++;
    }
  }

  if (!f)
    cout << "pairwise coprime";
  else {
    int g = num[1];
    for (int i = 2; i <= N; i++)
      g = gcd(g, num[i]);
    if (g == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <deque>
#include <iostream>
#include <list>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
const int BIG = 1000000007;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(1000001, 0);
  bool pc = true;
  bool sc = true;
  for (ll i = 0; i < n; ++i) {
    ll l;
    cin >> l;
    ++a[l];
  }

  for (ll i = 2; i < a.size(); ++i) {
    ll j = i * 2;
    ll k = a[i];
    while (j < a.size()) {
      if (a[j]) {
        k += a[j];
      }
      j += i;
    }
    if (k >= 2)
      pc = false;
    ;
    if (k == n)
      sc = false;
  }

  if (pc) {
    cout << "pairwise coprime" << endl;
  } else if (sc) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}


Error: 0

Fixed submission:

#include <deque>
#include <iostream>
#include <list>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
const int BIG = 1000000007;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(100001, 0);
  bool pc = true;
  bool sc = true;
  for (ll i = 0; i < n; ++i) {
    ll l;
    cin >> l;
    ++a[l];
    if (a[l] > 1)
      pc = false;
  }

  for (ll i = 2; i < a.size(); ++i) {
    ll j = i * 2;
    ll k = 0;
    if (a[i])
      ++k;
    while (j < a.size()) {
      if (a[j]) {
        if (k > 0)
          pc = false;
        k += a[j];
      }
      j += i;
    }
    if (k == n)
      sc = false;
  }

  if (pc) {
    cout << "pairwise coprime" << endl;
  } else if (sc) {
    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;

#define all(x) (x).begin(), (x).end()

using ll = long long;
using P = pair<int, int>;
using mp = map<string, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

vector<int> factor(int n) {
  vector<int> res;

  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res.push_back(i);
      n /= i;
    }
  }
  if (n != 1)
    res.push_back(n);

  return res;
}

int main(void) {

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

  int not_coprime = a[0];
  for (int i = 1; i < n; ++i) {
    not_coprime = gcd(not_coprime, a[i]);
  }
  if (not_coprime != 1) {
    cout << "not coprime"
         << "\\n";
    return 0;
  }

  set<int> pr;
  for (int i = 0; i < n; ++i) {
    vector<int> x = factor(a[i]);
    set<int> ps(all(x));

    for (auto v : ps) {
      if (pr.find(v) != pr.end()) {
        cout << "setwise coprime"
             << "\\n";
        return 0;
      }
      pr.insert(v);
    }
  }
  cout << "pairwise coprime"
       << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define endl "\\n"

using ll = long long;
using P = pair<string, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int a[1000005];

void enum_divisors(int N) {
  for (int i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      a[i]++;
      if (N / i != i)
        a[N / i]++;
    }
  }
}

int main(void) {

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

  for (int i = 2; i < 1000005; ++i) {
    if (a[i] == n) {
      cout << "not coprime"
           << "\\n";
      return 0;
    }
  }

  for (int i = 2; i < 1000005; ++i) {
    if (1 < a[i] && a[i] < n) {
      cout << "setwise coprime"
           << "\\n";
      return 0;
    }
  }

  cout << "pairwise coprime"
       << "\\n";

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

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

using ll = long long;
using P = pair<int, int>;
using mp = map<string, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

vector<int> sieve(int n) {
  vector<int> res(n);
  for (int i = 0; i < n; ++i)
    res[i] = i;
  for (int i = 2; i * i < n; ++i) {
    if (res[i] < i)
      continue;
    for (int j = i * i; j < n; j += i)
      if (res[j] == j)
        res[j] = i;
  }

  return res;
}

vector<int> factor(int n, const vector<int> &min_factor) {
  vector<int> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
  }

  return res;
}

int main(void) {

  int n;
  cin >> n;

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

  int x = a[0];
  for (int i = 0; i < n; ++i)
    x = gcd(x, a[i]);
  if (x != 1) {
    cout << "not coprime"
         << "\\n";
    return 0;
  }

  vector<int> b = sieve(1000005);
  set<int> prime;
  for (int i = 0; i < n; ++i) {
    vector<int> c = factor(a[i], b);
    set<int> ps(all(c));
    for (auto v : ps) {
      if (prime.find(v) != prime.end()) {
        cout << "setwise coprime"
             << "\\n";
        return 0;
      }
      prime.insert(v);
    }
  }

  cout << "pairwise coprime"
       << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define endl "\\n"

using ll = long long;
using P = pair<string, int>;
using mp = map<int, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int a[1000005];

void enum_divisors(int N) {
  for (int i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      a[i]++;
      if (N / i != i)
        a[N / i]++;
    }
  }
}

int main(void) {

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    enum_divisors(x);
  }

  for (int i = 2; i < 1000005; ++i) {
    if (a[i] == n) {
      cout << "not coprime"
           << "\\n";
      return 0;
    }
  }

  for (int i = 2; i < 1000005; ++i) {
    if (1 < a[i] && a[i] < n) {
      cout << "setwise coprime"
           << "\\n";
      return 0;
    }
  }

  cout << "pairwise coprime"
       << "\\n";

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

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector<vector<ll>>;

int N;
int a[1000000];
int b[1000001] = {0};
vector<int> v[1000001];

int prm[1000001];
void Eratosthenes(int N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  prm[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      prm[i] = i;
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
        prm[j] = i;
      }
    }
  }
}

int main() {
  cin >> N;
  int M = 0;
  rep(i, N) {
    cin >> a[i];
    M = max(M, a[i]);
  }
  Eratosthenes(M);
  // rep(i, M+1) {
  //   cout << prm[i] << " ";
  // }
  // cout << endl;

  bool f = false;
  rep(i, N) {
    int x = a[i];
    while (x != 1) {
      if (prm[x] != prm[x / prm[x]]) {
        b[prm[x]]++;
        if (b[prm[x]] >= 2) {
          f = true;
        }
        if (b[prm[x]] == N) {
          cout << "not coprime" << endl;
          return 0;
        }
      }
      x /= prm[x];
    }
  }
  if (f)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector<vector<ll>>;

int N;
int a[1000000];
int b[1000001] = {0};
vector<int> v[1000001];

int main() {
  cin >> N;
  rep(i, N) { cin >> a[i]; }
  sort(a, a + N);
  reverse(a, a + N);
  bool f = false;
  rep(i, N) {
    int x = a[i];
    for (int j = 2; j * j <= a[i]; j++) {
      if (x % j == 0) {
        // v[i].push_back(j);
        b[j]++;
        if (b[j] == N) {
          cout << "not coprime" << endl;
          return 0;
        }
        if (b[j] >= 2) {
          f = true;
        }
      }
      while (x % j == 0) {
        x /= j;
      }
    }
    if (x != 1) {
      // v[i].push_back(x);
      b[x]++;
      if (b[x] == N) {
        cout << "not coprime" << endl;
        return 0;
      }
      if (b[x] >= 2) {
        f = true;
      }
    }
  }
  if (f)
    cout << "setwise coprime" << endl;
  else
    cout << "pairwise coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 1000000007LL
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  int brr[n];
  int fre[1000001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    brr[i] = arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= arr[i]; j++) {
      if ((arr[i] % j) == 0)
        fre[j]++;
      while ((arr[i] % j) == 0) {
        arr[i] = arr[i] / j;
      }
    }
    if (arr[i] != 1)
      fre[arr[i]]++;
  }
  sort(fre, fre + 500000, greater<int>());
  if (fre[0] == 1 || fre[0] == 0) {
    cout << "pairwise coprime";
    return 0;
  }
  int ans = __gcd(brr[0], brr[1]);
  for (int i = 2; i < n; i++) {
    ans = __gcd(ans, brr[i]);
  }
  if (ans == 1) {
    cout << "setwise coprime";
    return 0;
  }
  cout << "not coprime";

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 1000000007LL
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  int brr[n];
  int fre[500000] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    brr[i] = arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= arr[i]; j++) {
      if ((arr[i] % j) == 0)
        fre[j]++;
      while ((arr[i] % j) == 0) {
        arr[i] = arr[i] / j;
      }
    }
    if (arr[i] != 1)
      fre[arr[i]]++;
  }
  sort(fre, fre + 500000, greater<int>());
  if (fre[0] == 1) {
    cout << "pairwise coprime";
    return 0;
  }
  int ans = __gcd(brr[0], brr[1]);
  for (int i = 2; i < n; i++) {
    ans = __gcd(ans, brr[i]);
  }
  if (ans == 1) {
    cout << "setwise coprime";
    return 0;
  }
  cout << "not coprime";

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

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

class dsu {
  vector<int> par;

public:
  dsu(int n) {
    par.resize(n);
    iota(par.begin(), par.end(), 0);
  }

  int find(int u) {
    if (u == par[u])
      return u;
    return par[u] = find(par[u]);
  }

  void join(int a, int b) {
    a = find(a);
    b = find(b);
    if (a != b)
      par[b] = a;
  }
};

const int nax = 1000123;
vector<vector<int>> v;
void pre() {
  v = vector<vector<int>>(nax);
  for (int i = 2; i < nax; i++) {
    if (v[i].empty()) {
      for (int j = i; j < nax; j += i) {
        v[j].push_back(i);
      }
    }
  }
}

signed main() {
  pre();
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a)
    cin >> i;
  int g = 0;
  for (auto i : a)
    g = __gcd(g, i);
  if (g != 1)
    cout << "not coprime" << endl;
  else {
    unordered_map<int, int> u;
    for (int i : a)
      for (auto j : v[i])
        u[j]++;
    bool ok = true;
    for (auto i : u)
      if (i.second > 1)
        ok = false;
    if (ok)
      cout << "pairwise coprime\\n";
    else
      cout << "setwise coprime\\n";
  }
}

Error: TLE

Fixed submission:

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

class dsu {
  vector<int> par;

public:
  dsu(int n) {
    par.resize(n);
    iota(par.begin(), par.end(), 0);
  }

  int find(int u) {
    if (u == par[u])
      return u;
    return par[u] = find(par[u]);
  }

  void join(int a, int b) {
    a = find(a);
    b = find(b);
    if (a != b)
      par[b] = a;
  }
};

signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a)
    cin >> i;
  int g = 0;
  for (auto i : a)
    g = __gcd(g, i);
  if (g != 1)
    cout << "not coprime" << endl;
  else {
    unordered_map<int, int> u;
    for (int i : a) {
      int x = i;
      for (int j = 2; j * j <= i; j++) {
        if (x % j == 0) {
          u[j]++;
          while (x % j == 0)
            x /= j;
        }
      }
      if (x > 1)
        u[x]++;
    }
    bool ok = true;
    for (auto i : u)
      if (i.second > 1)
        ok = false;
    if (ok)
      cout << "pairwise coprime\\n";
    else
      cout << "setwise coprime\\n";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int euclid(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  if (a % b == 0)
    return b;
  return euclid(b, a % b);
}

int main() {
  int N;
  bool pairwise = true;
  cin >> N;
  vector<int> count(1000001);
  int N_gcd = 1;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    count.at(a)++;

    if (i == 0)
      N_gcd = a;
    else
      N_gcd = euclid(N_gcd, a);
  }

  for (int i = 2; i < 1000001; i++) {
    int total = 0;
    for (int j = i; j < 1000001; j += i) {
      total += count.at(j);
    }
    if (total > 1) {
      pairwise = false;
      break;
    }
  }

  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (N_gcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int euclid(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  if (a % b == 0)
    return b;
  return euclid(b, a % b);
}

int main() {
  int N;
  bool pairwise = true;
  cin >> N;
  vector<int> count(1000000);
  int N_gcd = 1;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    count.at(a)++;

    if (i == 0)
      N_gcd = a;
    else
      N_gcd = euclid(N_gcd, a);
  }

  for (int i = 2; i < 1000000; i++) {
    int total = 0;
    for (int j = i; j < 1000000; j += i) {
      total += count.at(j);
    }
    if (total > 1) {
      pairwise = false;
      break;
    }
  }

  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (N_gcd == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 10;
int n, a[maxn], p[maxn], b[maxn];
vector<int> v;
void init() {
  for (int i = 2; i < 10006; i++) {
    if (p[i])
      continue;
    v.push_back(i);
    for (int j = i * i; j < 10006; j += i)
      p[j] = 1;
  }
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int main() {
  init();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int x = a[1];
  for (int i = 2; i <= n; i++)
    x = gcd(a[i], x);
  if (x != 1)
    cout << "not coprime";
  else {
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      int x = a[i], j = 0;
      if (x == 1)
        continue;
      while (x > 1) {
        if (x % v[j] == 0 && b[v[j]]) {
          flag = false;
          break;
        }
        while (x % v[j] == 0)
          x /= v[j], b[v[j]] = 1;
        j++;
        if (j >= v.size()) {
          if (b[x])
            flag = false;
          b[x] = 1;
          break;
        }
      }
      if (!flag)
        break;
    }
    if (flag)
      cout << "pairwise coprime";
    else
      cout << "setwise coprime";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 10;
int n, a[maxn], p[maxn], b[maxn];
vector<int> v;
void init() {
  for (int i = 2; i < 1000006; i++) {
    if (p[i])
      continue;
    v.push_back(i);
    for (int j = i * i; j < 1000006; j += i)
      p[j] = 1;
  }
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int main() {
  init();
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int x = a[1];
  for (int i = 2; i <= n; i++)
    x = gcd(a[i], x);
  if (x != 1)
    cout << "not coprime";
  else {
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      int x = a[i], j = 0;
      if (x == 1)
        continue;
      while (x > 1) {
        if (x % v[j] == 0 && b[v[j]]) {
          flag = false;
          break;
        }
        while (x % v[j] == 0)
          x /= v[j], b[v[j]] = 1;
        j++;
        if (j >= v.size())
          break;
      }
      if (!flag)
        break;
    }
    if (flag)
      cout << "pairwise coprime";
    else
      cout << "setwise coprime";
  }
  return 0;
}