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

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll cnt[1000006];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll allgcd = a[0];
  rep(i, n) allgcd = __gcd(allgcd, a[i]);
  if (allgcd > 1) {
    cout << "not coprime" << endl;
  } else {
    // 与えられた数をそれぞれ素因数分解していく
    rep(i, n) {
      ll now = a[i];
      for (ll j = 2; j * j <= now; j++) {
        if (now % j == 0) {
          while (now % j == 0)
            now /= j;
          cnt[j]++;
        }
      }
      if (now > 1)
        cnt[now]++;
    }
    for (int i = 2; i <= 1e6; i++) {
      if (cnt[i] > 1) {
        cout << "setwise coprime" << endl;
        return 0;
      }
    }
    cout << "pairwise coprime" << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll cnt[1000006];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll allgcd = a[0];
  rep(i, n) allgcd = __gcd(allgcd, a[i]);
  if (allgcd > 1) {
    cout << "not coprime" << endl;
  } else {
    // 与えられた数をそれぞれ素因数分解していく
    rep(i, n) {
      ll now = a[i];
      for (ll j = 2; j * j <= a[i]; j++) {
        if (now % j == 0) {
          while (now % j == 0)
            now /= j;
          cnt[j]++;
        }
      }
      if (now > 1)
        cnt[now]++;
    }
    for (int i = 2; i <= 1e6; i++) {
      if (cnt[i] > 1) {
        cout << "setwise coprime" << endl;
        return 0;
      }
    }
    cout << "pairwise coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long int;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int b[1000010] = {};
  rep(i, n) b[a[i]]++;

  bool flag1 = 0;
  for (int i = 2; i <= 1000000; i++) {
    int sum = 0;
    for (int j = i; j <= 1000000; j += i) {
      sum += b[j];
    }
    if (sum > 1)
      flag1 = 1;
  }

  int ans = 0;
  rep(i, n) { ans = __gcd(ans, a[i]); }

  if (flag1 == 0) {
    cout << "pairwise coprime" << endl;
  } else if (flag1 == 1 && ans == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long int;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;

int b[1000010] = {};
bool anspair = 0;

int main() {
  int n;
  cin >> n;
  int a[n];
  int top = 0;
  rep(i, n) {
    cin >> a[i];
    chmax(top, a[i]);
  }

  for (int i = 2; i <= top; i++) {
    rep(j, n) {
      if (a[j] % i == 0)
        b[i]++;
    }
    if (b[i] >= 2) {
      anspair = 1;
    }
  }
  int ans;
  rep(i, n) {
    if (i == 0) {
      ans = a[i];
    } else {
      ans = __gcd(ans, a[i]);
    }
  }

  if (anspair == 0) {
    cout << "pairwise coprime" << endl;
  } else if (anspair == 1 && ans == 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;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
ll dep(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return dep(b, a % b);
}
int main() {
  ll n;
  cin >> n;
  ll ch[1000010];
  for (ll i = 0; i < n; i++) {
    cin >> ch[i];
  }
  ll ch2[1000010] = {};
  for (ll i = 2; i < 1000010; i++) {
    if (ch2[i] != 0) {
      continue;
    }
    for (ll j = 1; i * j < 1000010; j++) {
      ll now = i * j;
      if (ch2[now] == 0) {
        ch2[i * j] = i;
      }
    }
  }
  // for(ll i=0;i<1000010;i++){
  // cout << i<< " "<<ch2[i]<<endl;
  //}
  ll ch3[1000010] = {};
  bool ans1 = true;
  // cout <<ans1<<endl;
  for (ll i = 0; i < n; i++) {
    ll now = ch[i];
    while (now != 1) {
      ll next = ch2[now];
      if (ch3[next] == 1) {
        ans1 = false;
        break;
      }
      ch3[next] = 1;
      while (now % next == 0) {
        now /= next;
      }
    }
    if (ans1 == false) {
      break;
    }
  }
  if (ans1) {
    cout << "pairwise coprime";
    return 0;
  }
  ll gcd = ch[0];
  for (ll i = 1; i < n; i++) {
    gcd = dep(max(gcd, ch[i]), min(gcd, ch[i]));
  }
  if (gcd == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  // your code goes here
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
ll dep(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return dep(b, a % b);
}
int main() {
  ll n;
  cin >> n;
  ll ch[1000010];
  for (ll i = 0; i < n; i++) {
    cin >> ch[i];
  }
  ll ch2[1000010] = {};
  for (ll i = 2; i < 1000010; i++) {
    if (ch2[i] != 0) {
      continue;
    }
    for (ll j = 1; i * j < 100010; j++) {
      ll now = i * j;
      if (ch2[now] == 0) {
        ch2[i * j] = i;
      }
    }
  }
  // for(ll i=0;i<1000010;i++){
  // cout << i<< " "<<ch2[i]<<endl;
  //}
  ll ch3[1000010] = {};
  bool ans1 = true;
  // cout <<ans1<<endl;
  for (ll i = 0; i < n; i++) {
    ll now = ch[i];
    while (now != 1) {
      ll next = ch2[now];
      if (ch3[next] == 1) {
        ans1 = false;
        break;
      }
      ch3[next] = 1;
      while (now % next == 0) {
        now /= next;
      }
    }
    if (ans1 == false) {
      break;
    }
  }
  if (ans1) {
    cout << "pairwise coprime";
    return 0;
  }
  ll gcd = ch[0];
  for (ll i = 1; i < n; i++) {
    gcd = dep(max(gcd, ch[i]), min(gcd, ch[i]));
  }
  if (gcd == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  // your code goes here
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int minPrimeFactor[1000001];
bool isPrime[1000001];
bool isExist[1000001];
int a[1000000];

int main() {
  rep(i, 1000001) {
    isPrime[i] = true;
    isExist[i] = false;
  }
  int n;
  cin >> n;
  rep(i, n) { cin >> a[i]; }

  int ans = 0;

  /* preprocess */
  for (int i = 2; i <= 1000000; i++) {
    if (isPrime[i]) {
      for (int j = i; j <= 1000000; j += i) {
        if (isPrime[j]) {
          minPrimeFactor[j] = i;
          isPrime[j] = false;
        }
      }
    }
  }
  minPrimeFactor[1] = 1;

  rep(i, n) {
    vector<int> factors;
    factors.push_back(minPrimeFactor[a[i]]);
    int next = a[i] / minPrimeFactor[a[i]];
    while (next != 1) {
      // cout << "next " << next << endl;
      int factor = minPrimeFactor[next];
      if (factor != factors[factors.size() - 1]) {
        factors.push_back(factor);
      }
      next = next / factor;
    }
    rep(j, factors.size()) {
      if (isExist[factors[j]] && factors[j] != 1)
        ans = 1;
      else
        isExist[factors[j]] = true;
    }
  }

  if (ans == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = a[0];
  rep(i, n - 1) { g = gcd(a[i + 1], g); }
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}
/*
 */


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

bool isPrime[1000];
bool isExist[1000000];
int a[1000000];

int main() {
  rep(i, 1000) { isPrime[i] = true; }
  rep(i, 1000000) { isExist[i] = false; }
  int n;
  cin >> n;

  int ans = 0;

  rep(i, n) {
    cin >> a[i];
    if (!isExist[a[i] - 1])
      isExist[a[i] - 1] = true;
    else if (a[i] != 1)
      ans = 1;
  }

  for (int i = 2; i < 1000; i++) {
    if (isPrime[i]) {
      for (int j = 2 * i; j < 1000; j += i) {
        isPrime[j] = false;
      }
    }
  }

  int primeCount = 0;
  for (int i = 2; i < 1000000; i++) {
    if (isPrime[i]) {
      primeCount++;
      int dividable = 0;
      rep(j, n) {
        if (a[j] % i == 0)
          dividable++;
      }
      if (dividable >= 2)
        ans = 1;
    }
  }
  // cout << "the number of prime is " << primeCount << endl;
  if (ans == 0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = a[0];
  rep(i, n - 1) { g = gcd(a[i + 1], g); }
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

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

#include <bits/stdc++.h>
#define ll long long int
#define MAXN 1000001
using namespace std;
ll spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;
  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}
void get(map<ll, ll> &ma, ll a[], ll n) {
  //	ll f=0;
  for (ll i = 0; i < n; i++) {
    while (a[i] != 1) {
      ma[spf[a[i]]]++;
      ll temp = spf[a[i]];
      // cout<<temp<<endl;
      while (spf[a[i]] == temp) {
        a[i] = a[i] / spf[a[i]];
      }
    }
  }
  ll gcd = 1, f = 0;
  map<ll, ll>::iterator it;
  for (it = ma.begin(); it != ma.end(); it++) {
    ll d = (it->second) / n;
    //	cout<<it->first<<" "<<it->second<<" "<<d<<endl;
    if (d != 0)
      gcd = gcd * (it->first);
    if (it->second != 1) {
      f = 1;
    }
  }
  if (f == 0) {
    cout << "pairwise coprime" << endl;
  } else if (gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
int main() {
  sieve();
  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> ma;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  get(ma, a, n);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define MAXN 100001
using namespace std;
ll spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;
  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}
void get(map<ll, ll> &ma, ll a[], ll n) {
  //	ll f=0;
  for (ll i = 0; i < n; i++) {
    while (a[i] != 1) {
      ma[spf[a[i]]]++;
      ll temp = spf[a[i]];
      // cout<<temp<<endl;
      while (spf[a[i]] == temp) {
        a[i] = a[i] / spf[a[i]];
      }
    }
  }
  ll gcd = 1, f = 0;
  map<ll, ll>::iterator it;
  for (it = ma.begin(); it != ma.end(); it++) {
    ll d = (it->second) / n;
    //	cout<<it->first<<" "<<it->second<<" "<<d<<endl;
    if (d != 0)
      gcd = gcd * (it->first);
    if (it->second != 1) {
      f = 1;
    }
  }
  if (f == 0) {
    cout << "pairwise coprime" << endl;
  } else if (gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
int main() {
  sieve();
  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> ma;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  get(ma, a, n);
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int A = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(A);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool pairwise = true;
  for (int i = 2; i < A; i++) {
    int cnt = 0;
    for (int j = i; j < A; j += i) {
      cnt += c[j];
    }
    if (cnt > 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;
    return 0;
  }

  cout << "not coprime" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);
vector<ll> prime;
vector<ll> eratosthenes(long long n) {
  vector<ll> is_prime(n + 1, true);
  for (ll i = 2; i * i <= n; i++) {
    if (is_prime[i]) {
      for (ll j = i + i; j <= n + 1; j += i) {
        is_prime[j] = false;
      }
    }
  }
  for (ll i = 2; i < is_prime.size(); i++) {
    if (is_prime[i]) {
      prime.push_back(i);
    }
  }
  return prime;
}

int main() { // TODO
  int N;
  cin >> N;
  vector<ll> A(1000005, 0);
  vector<ll> V(N);
  ll gmax = -1;
  rep(N) {
    ll a;
    cin >> a;
    gmax = max(gmax, a);
    A[a] = 1;
    V[i] = a;
  }

  bool is_pc = true;
  for (ll j; j < gmax; j++) {
    ll tmp = 0;
    for (ll i = j; i < gmax; i += j) {
      tmp += A[i];
    }
    if (tmp > 1) {
      is_pc = false;
      break;
    }
  }

  if (is_pc == true) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll g = 0;
  for (ll i = 0; i < N; i++) {
    g = __gcd(g, V[i]);
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

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

int main() {
  ios::sync_with_stdio(false);
  int n, a[1000006] = {}, g = 0, b[1000006] = {}, p[1000006] = {1, 1};
  vector<int> c;
  for (int i = 2; i <= 1000000; i++)
    if (!p[i]) {
      c.push_back(i);
      for (int j = i + i; j <= 1000000; j += i)
        p[j] = 1;
    }
  vector<int> f[1000006] = {};
  for (int i = 2; i <= 1000000; i++) {
    int j = i;
    for (int k : c) {
      if (k * k > j)
        break;
      if (j % k == 0) {
        f[i].push_back(k);
        while (j % k == 0)
          j /= k;
      }
    }
    if (j > 1)
      f[i].push_back(j);
  }
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i], g = gcd(g, a[i]);
  if (g != 1)
    cout << "not";
  else {
    for (int i = 0; i < n; i++) {
      for (int j : f[a[i]])
        b[j]++;
    }
    bool y = 0;
    for (int i = 1; i <= 1000000; i++)
      if (b[i] > 1) {
        y = 1;
        break;
      }
    if (y)
      cout << "setwise";
    else
      cout << "pairwise";
  }
  cout << " coprime";
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

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

int main() {
  ios::sync_with_stdio(false);
  int n, a[1000006] = {}, g = 0, b[1000006] = {};
  vector<int> f[1000006] = {};
  for (int i = 2; i <= 1000000; i++) {
    int j = i;
    for (int k = 2; k * k <= i; k++)
      if (j % k == 0) {
        f[i].push_back(k);
        while (j % k == 0)
          j /= k;
      }
    if (j > 1)
      f[i].push_back(j);
  }
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i], g = gcd(g, a[i]);
  if (g != 1)
    cout << "not";
  else {
    for (int i = 0; i < n; i++) {
      for (int j : f[a[i]])
        b[j]++;
    }
    bool y = 0;
    for (int i = 1; i <= 1000000; i++)
      if (b[i] > 1) {
        y = 1;
        break;
      }
    if (y)
      cout << "setwise";
    else
      cout << "pairwise";
  }
  cout << " coprime";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

template <typename T> struct PrimeFact {
  std::vector<T> spf;
  PrimeFact(T N) { init(N); }
  void init(T N) { // 前処理。spf を求める
    spf.assign(N + 1, 0);
    for (T i = 0; i <= N; i++)
      spf[i] = i;
    for (T i = 2; i * i <= N; i++) {
      if (spf[i] == i) {
        for (T j = i * i; j <= N; j += i) {
          if (spf[j] == j) {
            spf[j] = i;
          }
        }
      }
    }
  }
  std::map<T, T> get(T n) { // nの素因数分解を求める
    std::map<T, T> m;
    while (n != 1) {
      m[spf[n]]++;
      n /= spf[n];
    }
    return m;
  }
};

int main() {
  uint32_t N = 0;
  std::cin >> N;

  PrimeFact pf(1'000'000);

  std::map<uint32_t, uint32_t> prime;
  for (size_t i = 0; i < N; i++) {
    uint32_t a = 0;
    std::cin >> a;

    for (auto &&p : pf.get(a))
      prime[p.first]++;
  }

  bool pairwise = true;
  for (auto &&p : prime) {
    if (p.second == N) {
      std::cout << "not coprime" << std::endl;
      return 0;
    }
    if (p.second >= 2)
      pairwise = false;
  }

  std::cout << (pairwise ? "pairwise" : "setwise") << " coprime" << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

int main() {
  uint32_t N = 0;
  std::cin >> N;

  std::map<uint32_t, uint32_t> prime;

  for (size_t i = 0; i < N; i++) {
    uint32_t a = 0;
    std::cin >> a;
    for (size_t p = 2; p * p <= a; p++) {
      if (a % p == 0)
        prime[p]++;
      while (a % p == 0)
        a /= p;
    }
    if (a != 1)
      prime[a]++;
  }

  bool pairwise = true;
  for (auto p : prime) {
    if (p.second == N) {
      std::cout << "not coprime" << std::endl;
      return 0;
    }
    if (p.second >= 2)
      pairwise = false;
  }

  std::cout << (pairwise ? "pairwise" : "setwise") << " coprime" << std::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
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
ll a[maxn];
int mp[maxn];
int vis[maxn];

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll t = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    t = gcd(t, a[i]);
  }
  vector<int> cnt;
  for (int i = 2; i < maxn; i++) {
    if (vis[i])
      continue;
    cnt.pb(i);
    for (int j = i; j < maxn; j += i) {
      vis[j] = 1;
    }
  }
  if (t == 1) {
    for (int i = 1; i <= n; i++) {
      for (auto &v : cnt) {
        if (1ll * v * v > a[i])
          break;
        if (a[i] % v == 0) {
          mp[v]++;
          if (mp[v] > 1) {
            cout << "setwise coprime" << '\\n';
            return 0;
          }
          while (a[i] % v == 0)
            a[i] /= v;
        }
      }
      if (a[i] > 1)
        mp[a[i]]++;
      if (mp[a[i]] > 1) {
        cout << "setwise coprime" << '\\n';
        return 0;
      }
    }
    cout << "pairwise coprime" << '\\n';
  } else {
    cout << "not coprime" << '\\n';
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
ll a[maxn];
int mp[maxn];
int vis[maxn];

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll t = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    t = gcd(t, a[i]);
  }
  vector<int> cnt;
  for (int i = 2; i < maxn; i++) {
    if (vis[i])
      continue;
    cnt.pb(i);
    for (int j = i; j < maxn; j += i) {
      vis[j] = 1;
    }
  }
  if (t == 1) {
    for (int i = 1; i <= n; i++) {
      for (auto &v : cnt) {
        if (a[i] % v == 0) {
          mp[v]++;
          if (mp[v] > 1) {
            cout << "setwise coprime" << '\\n';
            return 0;
          }
          while (a[i] % v == 0)
            a[i] /= v;
        }
      }
    }
    cout << "pairwise coprime" << '\\n';
  } else {
    cout << "not coprime" << '\\n';
  }
}