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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main() {
  IOS;
  int n;
  cin >> n;
  vector<bool> s(1000005, 0);
  bool pairwise = 1;
  int total = 0;
  rep(i, 0, n) {
    int t;
    cin >> t;
    if (s[t] && t != 1)
      pairwise = 0;
    else if (!s[t]) {
      s[t] = 1;
      total++;
    }
  }
  vector<bool> checked(1000005, 0);
  int count = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (checked[i])
      continue;
    if (total == count)
      break;
    count = 0;
    for (int j = 1; i * j <= 1000000; j++) {
      checked[i * j] = 1;
      if (s[i * j] == 1)
        count++;
    }
    if (count >= 2)
      pairwise = 0;
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (count == total)
    cout << "not coprime" << endl;
  else
    cout << "setwise coprime" << endl;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main() {
  IOS;
  int n;
  cin >> n;
  vector<int> a(n);
  vector<bool> checked(1000000, 0);
  rep(i, 0, n) cin >> a[i];
  int count = 0;
  bool pairwise = 1;
  bool not_co = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (checked[i])
      continue;
    else {
      count = 0;
      rep(i, 0, n) {
        if (a[i] % i == 0)
          count++;
      }
      if (count >= 2)
        pairwise = 0;
      if (count == n) {
        not_co = 0;
        break;
      }
      for (int j = 2; i * j <= 1000000; j++)
        checked[i * j] = 1;
    }
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (not_co)
    cout << "not coprime" << endl;
  else
    cout << "setwise coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template <typename T> T gcd(T a, T b) { return (a % b) ? gcd(b, a % b) : b; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

int main(void) {
  int n;
  cin >> n;
  int a[n];
  vector<int> tmp(1000005, 0);
  REP(i, n) {
    cin >> a[i];
    tmp[a[i]]++;
  }

  bool pairwise = true;
  for (int i = 2; i < 1000005; i++) {
    int ctr = 0;
    for (int j = i; j < 1000005; j += i) {
      ctr += tmp[j];
    }
    if (ctr > 1) {
      pairwise = false;
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = 0;
  REP(i, n) { g = gcd(g, a[i]); }
  if (g == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template <typename T> T gcd(T a, T b) { return (a % b) ? gcd(b, a % b) : b; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }

const int max = 1000005;

struct Sieve {
  int n;
  vector<int> f, primes;

  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i < n; ++i) {
      if (f[i])
        continue;
      // 以下はすでに素数のみ
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        // これによりiの倍数をマークできる
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }

  set<int> factor(int x) {
    set<int> res;
    while (x != 1) {
      res.insert(f[x]);
      x /= f[x];
    }
    return res;
  }
};

int main(void) {
  Sieve sieve(1e6 + 5);
  // int pri = sieve.primes.size();
  // vector<int> primes(pri, 0);

  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  vector<int> tmp(n + 4, 0);

  REP(i, n) {
    auto fi = sieve.factor(a[i]);
    for (auto p : fi) {
      tmp[p]++;
    }
  }

  bool ispair = true, isset = true;
  int g = a[0];
  REP(i, n) g = gcd(g, a[i]);
  REP(i, n) {
    if (sieve.isPrime(i)) {
      if (tmp[i] != 1 && tmp[i] != 0)
        ispair = false;
      // if(tmp[i] == n) isset = false;
    }
  }
  if (ispair) {
    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;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

int main() {
  ll i, j, n, m;
  cin >> n;
  vector<ll> a(n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  map<ll, bool> mp;
  for (i = 0; i < n; i++) {
    ll cur = a[i];
    ll pr = 0;
    while (cur % 2 == 0) {
      cur /= 2;
      pr = 1;
    }
    if (pr == 1) {
      if (mp.find(2) == mp.end()) {
        mp[2] = 1;
      } else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\\n";
        else
          cout << "not coprime\\n";
        return 0;
      }
    }
    for (j = 3; j * j <= cur; j += 2) {
      ll pr = 0;
      while (cur % j == 0) {
        cur /= j;
        pr = 1;
      }
      if (pr == 1) {
        if (mp.find(j) == mp.end()) {
          mp[j] = 1;
        } else {
          ll gcd = 0;
          for (ll k = 0; k < n; k++)
            gcd = __gcd(gcd, a[k]);
          if (gcd == 1)
            cout << "setwise coprime\\n";
          else
            cout << "not coprime\\n";
          return 0;
        }
      }
    }
    if (cur != 1) {
      if (mp.find(cur) == mp.end())
        mp[cur] = 1;
      else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\\n";
        else
          cout << "not coprime\\n";
        return 0;
      }
    }
  }
  cout << "pairwise coprime\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

int main() {
  ll i, j, n, m;
  cin >> n;
  vector<ll> a(n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  map<ll, bool> mp;
  for (i = 0; i < n; i++) {
    ll cur = a[i];
    ll pr = 0;
    while (cur % 2 == 0) {
      cur /= 2;
      pr = 1;
    }
    if (pr == 1) {
      if (mp.find(2) == mp.end()) {
        mp[2] = 1;
      } else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\\n";
        else
          cout << "not coprime\\n";
        return 0;
      }
    }
    for (j = 3; j <= cur; j += 2) {
      ll pr = 0;
      while (cur % j == 0) {
        cur /= j;
        pr = 1;
      }
      if (pr == 1) {
        if (mp.find(j) == mp.end()) {
          mp[j] = 1;
        } else {
          ll gcd = 0;
          for (ll k = 0; k < n; k++)
            gcd = __gcd(gcd, a[k]);
          if (gcd == 1)
            cout << "setwise coprime\\n";
          else
            cout << "not coprime\\n";
          return 0;
        }
      }
    }
    if (cur != 1) {
      if (mp.find(cur) == mp.end())
        mp[cur] = 1;
      else {
        ll gcd = 0;
        for (ll k = 0; k < n; k++)
          gcd = __gcd(gcd, a[k]);
        if (gcd == 1)
          cout << "setwise coprime\\n";
        else
          cout << "not coprime\\n";
        return 0;
      }
    }
  }
  cout << "pairwise coprime\\n";
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const int Max_A = 1e6 + 5;
const int INF = 1e8;

int divisor[Max_A];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  rep(i, Max_A) divisor[i] = i;
  for (int i = 2; i * i < Max_A; i++) {
    if (divisor[i] == i) {
      for (int j = 2; j * i < Max_A; j++)
        divisor[j * i] = i;
    }
  }
  map<int, int> mp;
  rep(i, N) {
    int a = A[i];
    vector<int> p;
    while (a != 1) {
      int s = p.size();
      if (s == 0)
        p.emplace_back(divisor[a]);
      else if (divisor[a] != p[s - 1]) {
        p.emplace_back(divisor[a]);
      }
      a /= divisor[a];
    }
    rep(j, p.size()) mp[p[j]]++;
  }
  bool pairwise = true, setwise = true;
  for (auto itr : mp) {
    int num = itr.second;
    if (num >= 2)
      pairwise = false;
    if (num == N)
      setwise = false;
  }
  rep(i, N) if (A[i] == 1) setwise = true;
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (setwise)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const int Max_A = 1e6 + 5;
const int INF = 1e8;

int divisor[Max_A];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  rep(i, Max_A) divisor[i] = i;
  for (int i = 2; i * i < Max_A; i++) {
    if (divisor[i] == i) {
      for (int j = 2; j * i < Max_A; j++)
        divisor[j * i] = i;
    }
  }
  map<int, int> mp;
  rep(i, N) {
    int a = A[i];
    vector<int> p;
    while (a != divisor[a]) {
      a /= divisor[a];
      int s = p.size();
      if (divisor[a] != p[s - 1])
        p.emplace_back(divisor[a]);
    }
    rep(j, p.size()) mp[p[j]]++;
    if (a != 1)
      mp[a]++;
  }
  bool pairwise = true, setwise = true;
  for (auto itr : mp) {
    int num = itr.second;
    if (num >= 2)
      pairwise = false;
    if (num == N)
      setwise = false;
  }
  rep(i, N) if (A[i] == 1) setwise = true;
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (setwise)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const int Max_A = 1e6;
const int INF = 1e8;

bool prime[Max_A];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> p;
  rep(i, Max_A) prime[i] = true;
  for (int i = 2; i * i <= Max_A; i++) {
    if (prime[i]) {
      p.emplace_back(i);
      for (int j = 2; j * i <= Max_A; j++)
        prime[j * i] = false;
    }
  }
  map<int, int> mp;
  rep(i, N) {
    int a = A[i];
    rep(j, p.size()) {
      if (a % p[j] == 0)
        mp[p[j]]++;
      while (a % p[j] == 0)
        a /= p[j];
    }
    if (a != 1)
      mp[a]++;
  }
  bool pairwise = true, setwise = true;
  for (auto itr : mp) {
    int num = itr.second;
    if (num >= 2)
      pairwise = false;
    if (num == N)
      setwise = false;
  }
  rep(i, N) if (A[i] == 1) setwise = true;
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (setwise)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const int Max_A = 1e6;
const int INF = 1e8;

bool prime[Max_A + 5];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> p;
  rep(i, Max_A + 5) prime[i] = true;
  for (int i = 2; i <= Max_A; i++) {
    if (prime[i]) {
      p.emplace_back(i);
      for (int j = 2; j * i <= Max_A; j++)
        prime[j] = false;
    }
  }
  map<int, int> mp;
  rep(i, N) {
    int a = A[i];
    rep(j, p.size()) {
      if (a % p[j] == 0)
        mp[j]++;
    }
  }
  bool pairwise = true, setwise = true;
  for (auto itr : mp) {
    int num = itr.second;
    if (num >= 2)
      pairwise = false;
    if (num == N)
      setwise = false;
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else if (setwise)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;

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

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e4 + 7;

vector<bool> pm(N, false);

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

void getPrimes(vector<int> &primes) {
  for (int i = 2; i < N; i++) {
    if (!pm[i]) {
      primes.push_back(i);
      for (int j = i; j < N; j += i) {
        pm[j] = true;
      }
    }
  }
}

int main() {

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

  int n;
  cin >> n;

  vector<int> primes;
  getPrimes(primes);

  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    // arr[i] = rand() % ( 1000000);
  }

  int ans = arr[0];
  for (int i = 1; i < n; i++) {
    ans = gcd(ans, arr[i]);
  }

  if (ans > 1) {
    cout << "not coprime" << endl;
  } else {
    bool flag = true;
    unordered_set<int> hset;
    for (int j = 0; j < n; j++) {
      for (int i = 0; primes[i] * primes[i] <= arr[j]; i++) {
        if (arr[j] % primes[i] == 0) {
          if (hset.find(primes[i]) != hset.end()) {
            flag = false;
            break;
          }
          hset.insert(primes[i]);

          while (arr[j] % primes[i] == 0) {
            arr[j] = arr[j] / primes[i];
          }
        }
      }

      if (arr[j] > 1) {
        if (hset.find(arr[j]) != hset.end()) {
          flag = false;
          break;
        }
        hset.insert(arr[j]);
      }

      if (!flag) {
        break;
      }
    }

    if (flag)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e6 + 7;

vector<bool> pm(N, false);

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

void getPrimes(vector<int> &primes) {
  for (int i = 2; i < N; i++) {
    if (!pm[i]) {
      primes.push_back(i);
      for (int j = i; j < N; j += i) {
        pm[j] = true;
      }
    }
  }
}

int main() {

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

  int n;
  cin >> n;

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

  int ans = arr[0];
  for (int i = 1; i < n; i++) {
    ans = gcd(ans, arr[i]);
  }

  if (ans > 1) {
    cout << "not coprime" << endl;
  } else {
    vector<int> primes;
    getPrimes(primes);

    bool flag = true;
    for (int i = 0; i < primes.size(); i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++) {
        if (arr[j] % primes[i] == 0) {
          cnt++;
          while (arr[j] % primes[i] == 0) {
            arr[j] = arr[j] / primes[i];
          }
        }
      }
      if (cnt >= 2) {
        flag = false;
        break;
      }
    }

    if (flag)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
bool p[1000006];
long long r[1000005], y, o, k[1000006], b, u, a, ans;
int gp() {
  for (int i = 2; i <= 1000000; i++) {
    if (p[i] == 0) {
      for (int j = i * 2; j <= 1000000; j += i)
        p[j] = 1;
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    if (p[i] == 0) {
      r[y] = i;
      y++;
    }
  }
  return 0;
}
int main() {
  gp();
  cin >> a;
  for (int i = 0; i < a; i++) {
    u = 1;
    cin >> b;
    for (int j = 0; r[j] <= sqrt(b) && u == 1; j++) {
      if (b % r[j] == 0) {
        while (b % r[j] == 0)
          b /= r[j];
        k[r[j]]++;
        u = 1;
      }
    }
    k[b]++;
  }
  o = 1;
  for (int i = 2; i <= 1000000; i++) {
    if (k[i] >= 2)
      ans = max(ans, k[i]);
  }
  if (ans <= 1)
    cout << "pairwise coprime" << endl;
  else if (ans < a)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool p[1000006];
long long r[1000005], y, o, k[1000006], b, u, a, ans;
int gp() {
  for (int i = 2; i <= 1000000; i++) {
    if (p[i] == 0) {
      for (int j = i * 2; j <= 1000000; j += i)
        p[j] = 1;
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    if (p[i] == 0) {
      r[y] = i;
      y++;
    }
  }
}
int main() {
  gp();
  cin >> a;
  for (int i = 0; i < a; i++) {
    u = 1;
    cin >> b;
    for (int j = 0; r[j] <= sqrt(b) && u == 1; j++) {
      u = 0;
      if (b % r[j] == 0) {
        while (b % r[j] == 0)
          b /= r[j];
        k[r[j]]++;
        u = 1;
      }
    }
    k[b]++;
  }
  o = 1;
  for (int i = 0; i <= 1000000; i++) {
    if (k[i] >= 2)
      ans = max(ans, k[i]);
  }
  if (ans <= 1)
    cout << "pairwise coprime" << endl;
  else if (ans < a)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

int arr[1000001];
int main() {
  fast int n, z;
  cin >> n;
  int g;
  bool b = 1;
  for (int i = 0; i < n; i++) {
    cin >> z;
    if (i == 0)
      g = z;
    else
      g = __gcd(z, g);
    if (b) {
      int s = sqrt(z);
      for (int j = 2; j <= s; j++) {
        if (z % j == 0) {
          if (arr[j] != 0)
            b = 0;
          arr[j]++;
          while (z % j == 0)
            z /= j;
        }
      }
      if (z != 1) {
        if (arr[z] != 0)
          b = 0;
        arr[z]++;
      }
    }
  }
  if (b)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";

  return 0;
}


Error: WA

Fixed submission:

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

int arr[100001];
int main() {
  fast int n, z;
  cin >> n;
  int g;
  bool b = 1;
  for (int i = 0; i < n; i++) {
    cin >> z;
    if (i == 0)
      g = z;
    else
      g = __gcd(z, g);
    if (b) {
      int s = sqrt(z);
      for (int j = 2; j <= s; j++) {
        if (z % j == 0) {
          if (arr[j] != 0)
            b = 0;
          arr[j]++;
          while (z % j == 0)
            z /= j;
        }
      }
      if (z != 1) {
        if (arr[z] != 0)
          b = 0;
        arr[z]++;
      }
    }
  }
  if (b)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";

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

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

const int N = 1e6 + 3;
int n;
ll a[N], f[N];

vector<ll> primes;
bitset<N> v;
void init() {
  for (ll i = 2; i < N; ++i) {
    if (!v[i]) {
      primes.push_back(i);
      for (ll j = i + i; j < N; j += i)
        v[j] = 1;
    }
  }
}

void solve() {
  cin >> n;
  bool flg = 0;
  ll g = 0;
  for (int i = 0; i < n; ++i) {
    ll t;
    cin >> t;
    a[i] = t;
    g = __gcd(g, a[i]);
    for (int j = 0; j < (int)primes.size() && primes[j] * primes[j] <= t; ++j) {
      if (t % primes[j] == 0) {
        int cnt = 0;
        while (t % primes[j] == 0)
          t /= primes[j], cnt++;
        if (f[primes[j]] != 0)
          flg = 1;
        f[primes[j]] += cnt;
      }
    }
    if (t > 1) {
      if (f[t] > 0)
        flg = 1;
      f[t]++;
    }
  }
  if (!flg && (g == 1)) {
    cout << "pairwise coprime\\n";
  } else if (g == 1) {
    cout << "setwise coprime\\n";
  } else {
    cout << "not coprime\\n";
  }
}

int main() {
  init();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--)
    solve();
  return 0;
}


Error: TLE

Fixed submission:

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

const int N = 1e6 + 3;
int n;
int a[N], f[N];

vector<int> primes;
void init() {
  bitset<N> v;
  for (int i = 2; i < N; ++i) {
    if (!v[i]) {
      primes.push_back(i);
      for (int j = i + i; j < N; j += i)
        v[j] = 1;
    }
  }
}

void solve() {
  cin >> n;
  bool flg = 0;
  int g = 0;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a[i] = t;
    g = __gcd(g, a[i]);
    for (int j = 0; j < (int)primes.size() && t != 1; ++j) {
      if (t % primes[j] == 0) {
        int cnt = 0;
        while (t % primes[j] == 0)
          t /= primes[j], cnt++;
        if (f[primes[j]] != 0)
          flg = 1;
        f[primes[j]] += cnt;
      }
    }
  }
  if (!flg) {
    cout << "pairwise coprime\\n";
  } else if (g == 1) {
    cout << "setwise coprime\\n";
  } else {
    cout << "not coprime\\n";
  }
}

int main() {
  init();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--)
    solve();
  return 0;
}