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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

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

int main() {
  int n, x, flag, flag2 = 1;
  cin >> n;
  vector<int> a(n);
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n && flag2 == 1; i++) {
    x = a[i];
    for (int j = 2; j <= 1000 && x != 1; j++) {
      flag = 0;
      while (x % j == 0) {
        x /= j;
        flag = 1;
      }
      if (flag && s.find(j) == s.end()) {
        s.insert(j);
      } else if (flag) {
        flag2 = 0;
        break;
      }
    }
    if (x != 1 && s.find(x) == s.end()) {
      s.insert(x);
    } else if (x != 1) {
      flag2 = 0;
      break;
    }
  }
  if (flag2 == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  for (int i = 0; i < n; i++) {
    g = gcd(g, a[i]);
  }
  cout << (g == 1 ? "setwise coprime" : "not coprime") << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

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

int main() {
  int n, x, flag, flag2 = 1;
  cin >> n;
  vector<int> a(n);
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n && flag2 == 1; i++) {
    x = a[i];
    for (int j = 2; j <= 1000; j++) {
      flag = 0;
      while (x % j == 0) {
        x /= j;
        flag = 1;
      }
      if (flag && s.find(j) == s.end()) {
        s.insert(j);
      } else if (flag) {
        flag2 = 0;
        break;
      }
    }
    if (x != 1 && s.find(x) == s.end()) {
      s.insert(x);
    } else if (x != 1) {
      flag2 = 0;
      break;
    }
  }
  if (flag2 == 1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = a[0];
  for (int i = 0; i < n; i++) {
    g = gcd(g, a[i]);
  }
  cout << (g == 1 ? "setwise coprime" : "not coprime") << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

const int maxn = 1000005;
int n, a, prime[maxn];
set<int> st, st2, tmp;

int main() {
  cin >> n;
  for (int i = 2; i < maxn; i++) {
    if (!prime[i]) {
      for (int j = i; j < maxn; j += i) {
        prime[j] = i;
      }
    }
  }
  cin >> a;
  while (prime[a]) {
    st.insert(prime[a]);
    int x = prime[a];
    while (a % x == 0)
      a /= x;
  }
  st2 = st;
  bool pairwise = true;
  for (int i = 1; i < n; i++) {
    cin >> a;
    tmp.clear();
    for (auto j : st2) {
      if (a % j == 0)
        tmp.insert(j);
    }
    st2 = tmp;
    if (pairwise) {
      while (prime[a]) {
        if (st.count(prime[a]))
          pairwise = false;
        st.insert(prime[a]);
        int x = prime[a];
        while (a % x == 0)
          a /= x;
      }
    }
  }
  if (pairwise)
    cout << "pairwise coprime\\n";
  else if (!st2.size())
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}


Error: 0

Fixed submission:

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

const int maxn = 100005;
int n, a, prime[maxn];
set<int> st, st2;

int main() {
  cin >> n;
  for (int i = 2; i < maxn; i++) {
    if (!prime[i]) {
      for (int j = i; j < maxn; j += i) {
        prime[j] = i;
      }
    }
  }
  cin >> a;
  while (prime[a]) {
    st.insert(prime[a]);
    int x = prime[a];
    while (a % x == 0)
      a /= x;
  }
  st2 = st;
  bool pairwise = true;
  for (int i = 1; i < n; i++) {
    cin >> a;
    set<int> tmp;
    for (auto j : st2) {
      if (a % j == 0)
        tmp.insert(j);
    }
    st2 = tmp;
    while (prime[a]) {
      if (st.count(prime[a]))
        pairwise = false;
      st.insert(prime[a]);
      int x = prime[a];
      while (a % x == 0)
        a /= x;
    }
  }
  if (pairwise)
    cout << "pairwise coprime\\n";
  else if (!st2.size())
    cout << "setwise coprime\\n";
  else
    cout << "not coprime\\n";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl '\\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;

ll n, a[1000005], x;
set<ll> myset;
bool f = true;
bool is_prime(ll x) {
  if (x <= 1)
    return false;
  for (ll i = 2; i <= (ll)sqrt(x); ++i)
    if (x % i == 0)
      return false;
  return true;
}
void factorize(ll x) {
  if (!f)
    return;
  ll tec = 1;
  if (is_prime(x)) {
    if (myset.find(x) != myset.end())
      f = false;
    myset.insert(x);
    return;
  }
  bool flag;
  while (x > 1) {
    ++tec;
    flag = false;
    while (x % tec == 0) {
      flag = true;
      x /= tec;
    }
    if (flag) {
      if (myset.find(tec) != myset.end())
        f = false;
      myset.insert(tec);
      if (is_prime(x)) {
        if (myset.find(x) != myset.end())
          f = false;
        myset.insert(x);
        return;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (ll i = 1; i <= n; ++i)
    cin >> a[i];
  x = a[1];
  for (ll i = 2; i <= n; ++i) {
    x = __gcd(a[i], x);
  }
  for (ll i = 1; i <= n; ++i)
    factorize(a[i]);
  if (f) {
    cout << "pairwise coprime";
    return 0;
  }
  if (!f && x == 1) {
    cout << "setwise coprime";
    return 0;
  }
  cout << "not coprime";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;

ll n, a[1000005], x;
set<ll> myset;
bool f = true;
bool is_prime(ll x) {
  if (x <= 1)
    return false;
  for (ll i = 2; i <= (ll)sqrt(x); ++i)
    if (x % i == 0)
      return false;
  return true;
}
void factorize(ll x) {
  ll tec = 1;
  if (is_prime(x)) {
    if (myset.find(x) != myset.end())
      f = false;
    myset.insert(x);
    return;
  }
  bool flag;
  while (x > 1) {
    ++tec;
    flag = false;
    while (x % tec == 0) {
      flag = true;
      x /= tec;
    }
    if (flag) {
      if (myset.find(tec) != myset.end())
        f = false;
      myset.insert(tec);
      if (is_prime(x)) {
        if (myset.find(x) != myset.end())
          f = false;
        myset.insert(x);
        return;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (ll i = 1; i <= n; ++i)
    cin >> a[i];
  x = a[1];
  for (ll i = 2; i <= n; ++i) {
    x = __gcd(a[i], x);
  }
  for (ll i = 1; i <= n; ++i)
    factorize(a[i]);
  if (f) {
    cout << "pairwise coprime";
    return 0;
  }
  if (!f && x == 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 rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  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;
}

std::vector<int> factor(int n, const std::vector<int> &min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<int> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  map<int, int> m;
  vector<int> min_fac = sieve(2000000);
  rep(i, n) {
    set<int> s;
    if (a[i] == 1)
      continue;
    vector<int> v = factor(a[i], min_fac);
    for (auto j : v) {
      s.insert(j);
    }
    for (auto j : s) {
      m[j]++;
    }
  }
  bool f = false;
  for (auto i : m) {
    if (i.second == n)
      f = true;
  }
  if (f) {
    cout << "not coprime";
  } else {
    bool pw = true;
    for (auto i : m) {
      if (i.second > 1) {
        pw = false;
      }
    }
    if (pw) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

map<ll, ll> prime_factors(ll n) {
  map<ll, ll> res;
  if (n == 1) {
    res[n] = 1;
    return res;
  }
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) {
    res[n] = 1;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  map<int, int> m;
  rep(i, n) {
    set<int> s;
    if (a[i] == 1)
      continue;
    map<ll, ll> pf = prime_factors(a[i]);
    for (auto j : pf) {
      m[j.first]++;
    }
  }
  bool f = false;
  for (auto i : m) {
    // cout << i.first << ' ' << i.second << endl;
    if (i.second == n)
      f = true;
  }
  if (f) {
    cout << "not coprime";
  } else {
    bool pw = true;
    for (auto i : m) {
      if (i.second > 1) {
        pw = false;
      }
    }
    if (pw) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

// Problem Code: abc177_e

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

string coprime(int N, vector<int> &A) {
  int g = A[0], mx = *max_element(A.begin(), A.end());
  vector<bool> is_factor(mx);

  // gcd of all the elements
  for (int &x : A)
    g = __gcd(x, g);
  if (g > 1)
    return "not coprime";

  // check for pairwise coprime
  for (int x : A) {
    for (int y = 2; y * y <= x; y++)
      if (x % y == 0) {
        if (is_factor[y])
          return "setwise coprime";
        while (x % y == 0)
          x /= y;
        is_factor[y] = true;
      }
    if (x > 1) {
      if (is_factor[x])
        return "setwise coprime";
      is_factor[x] = true;
    }
  }

  return "pairwise coprime";
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  cout << coprime(N, A);
  return 0;
}

Error: TLE

Fixed submission:

// Problem Code: abc177_e

#include <bits/stdc++.h>

using namespace std;

string E(int N, vector<int> &A) {
  int g = A[0], max_a = 1e6;
  vector<bool> is_prime(max_a + 1);

  for (int i = 1; i < N; i++)
    g = __gcd(A[i], g);
  if (g > 1)
    return "not coprime";

  // sieve of eratosthenes
  for (int a = 2; a <= max_a; a++)
    if (is_prime[a]) {
      if ((long long)a * a > max_a)
        continue;
      for (int i = a * a; i <= max_a; i += a)
        is_prime[i] = false;
    }

  // check is all elements are co-prime
  vector<int> B;
  for (int &x : A) {
    if (!is_prime[x])
      B.push_back(x);
  }

  for (int i = 0; i < B.size(); i++)
    for (int j = i + 1; j < B.size(); j++)
      if (__gcd(B[i], B[j]) > 1)
        return "setwise coprime";

  return "pairwise coprime";
}

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

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  cout << E(N, A);

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

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define INF 1000000000

ll n, a[1000001];

bool pairwise() {
  ll factors[1000001] = {};
  for (ll i = 0; i < n; i++) {

    ll x = a[i];
    for (ll j = 1; j * j <= x; j++) {

      if (x % j == 0) {

        factors[j]++;

        if (j > 1 && factors[j] == 2)
          return false;

        if (j != x / j) {
          factors[x / j]++;
          if (factors[x / j] == 2)
            return false;
        }
        // x /= j;
      }
    }
  }
  return true;
}

bool setwise() {
  ll res = a[0];
  for (ll i = 1; i < n; i++)
    res = __gcd(res, a[i]);
  return res == 1LL;
}

void test_case() {
  cin >> n;

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

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

int main() {
  fastio
  // int t;
  // cin >> t;
  // while (t--)
  test_case();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define INF 1000000000

ll n, a[1000001];

bool pairwise() {
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      if (__gcd(a[i], a[j]) > 1)
        return false;
    }
  }
  return true;
}

bool setwise() {
  ll res = a[0];
  for (ll i = 1; i < n; i++)
    res = __gcd(res, a[i]);
  return res == 1LL;
}

void test_case() {
  cin >> n;

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

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

int main() {
  fastio
  // int t;
  // cin >> t;
  // while (t--)
  test_case();
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, maxi, a[1000010], cnt[1000010];
vector<int> v;
int main() {
  for (int i = 2; i <= 1000; i++) {
    bool flag = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = false;
      }
    }
    if (flag) {
      v.push_back(i);
    }
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    for (int j = 0; j < v.size(); j++) {
      if (a[i] % v[j] == 0) {
        cnt[v[j]]++;
      }
      while (a[i] % v[j] == 0) {
        a[i] /= v[j];
      }
    }
    if (a[i] != 1) {
      cnt[a[i]]++;
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    maxi = max(maxi, cnt[i]);
  }
  if (maxi == n) {
    printf("not coprime");
  } else if (maxi <= 1) {
    printf("pairwise coprime");
  } else {
    printf("setwise coprime");
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, a[1000010], cnt[1000010];
vector<int> v;
int main() {
  for (int i = 2; i <= 1000; i++) {
    bool flag = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = false;
      }
    }
    if (flag) {
      v.push_back(i);
    }
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    for (int j = 0; v[j] * v[j] <= a[i]; j++) {
      if (a[i] % v[j] == 0) {
        cnt[v[j]]++;
      }
      while (a[i] % v[j] == 0) {
        a[i] /= v[j];
      }
    }
    cnt[a[i]]++;
  }
  int mini = n;
  int maxi = 0;
  for (int i = 0; i < v.size(); i++) {
    mini = min(mini, cnt[v[i]]);
    maxi = max(maxi, cnt[v[i]]);
  }
  if (maxi == n) {
    printf("not coprime");
  } else if (maxi == 1) {
    printf("pairwise coprime");
  } else {
    printf("setwise coprime");
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

int isprime[MAX];
// to store smallest prime factor of number
void sieve() {
  for (int i = 1; i < MAX; ++i)
    isprime[i] = i;

  for (int i = 2; i < MAX; ++i) {
    if (i == isprime[i]) {
      for (int j = 2 * i; j <= MAX; j += i) {
        if (isprime[j] == j)
          isprime[j] = i;
      }
    }
  }
}
// A O(log n) function returning primefactorization

vector<int> factorize(int x) {
  vector<int> res;
  while (x != 1) {
    res.push_back(isprime[x]);
    x = x / isprime[x];
  }
  return res;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  sieve();

  int testCases = 1;
  //  cin >> testCases;

  while (testCases--) {
    int n, i;
    cin >> n;

    int a[n];

    for (i = 0; i < n; ++i)
      cin >> a[i];

    int GCD = a[0];
    for (i = 1; i < n; ++i) {
      GCD = __gcd(GCD, a[i]);
    }
    map<int, int> mp;
    for (i = 0; i < n; ++i) {
      vector<int> y = factorize(a[i]);
      set<int> X;

      for (int e : y)
        X.insert(e);

      for (auto e : X)
        mp[e]++;
    }
    bool flg = false;
    for (auto it : mp) {
      if (it.second > 1) {
        flg = true;
        break;
      }
    }

    if (!flg and GCD == 1) {
      cout << "pairwise coprime";
    } else {
      if (GCD == 1)
        cout << "setwise coprime";
      else
        cout << "not coprime";
    }

    cout << '\\n';
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 4;

int isprime[MAX];
// to store smallest prime factor of number
void sieve() {
  for (int i = 1; i < MAX; ++i)
    isprime[i] = i;

  for (int i = 2; i < MAX; ++i) {
    if (i == isprime[i]) {
      for (int j = 2 * i; j <= MAX; j += i) {
        if (isprime[j] == j)
          isprime[j] = i;
      }
    }
  }
}
// A O(log n) function returning primefactorization

vector<int> factorize(int x) {
  vector<int> res;
  while (x != 1) {
    res.push_back(isprime[x]);
    x = x / isprime[x];
  }
  return res;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  sieve();

  int testCases = 1;
  cin >> testCases;

  while (testCases--) {
    int n, i;
    cin >> n;

    int a[n];

    for (i = 0; i < n; ++i)
      cin >> a[i];

    int GCD = a[0];
    for (i = 1; i < n; ++i) {
      GCD = __gcd(GCD, a[i]);
    }
    map<int, int> mp;
    for (i = 0; i < n; ++i) {
      vector<int> y = factorize(a[i]);
      set<int> X;

      for (int e : y)
        X.insert(e);

      for (auto e : X)
        mp[e]++;
    }
    bool flg = false;
    for (auto it : mp) {
      if (it.second > 1) {
        flg = true;
        break;
      }
    }

    if (!flg) {
      cout << "pairwise coprime";
    } else {
      if (GCD == 1)
        cout << "setwise coprime";
      else
        cout << "no coprime";
    }

    cout << '\\n';
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;

bool isprime(ll n) {
  if (n == 1)
    return false;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int cnt[1000000] = {0};
void prime_factor(int n) {
  for (int i(2); i * i <= n; i++) {
    bool flag(true);
    while (n % i == 0) {
      if (flag) {
        ++cnt[i];
        flag = false;
      }
      n /= i;
    }
  }
  if (n != 1)
    cnt[n]++;
  return;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i(0); i < N; i++)
    cin >> A[i];
  for (int i(0); i < N; i++) {
    prime_factor(A[i]);
  }
  int maxi(0);
  // for(int i(0);i<10;i++){
  //   cout << cnt[i] << " ";
  // }
  // cout << endl;
  for (int i(0); i < 1000000; i++) {
    maxi = max(maxi, cnt[i]);
  }
  // cout << maxi << endl;
  if (maxi <= 1)
    cout << "pairwise coprime" << endl;
  else if (maxi < N)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;

bool isprime(ll n) {
  if (n == 1)
    return false;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i(0); i < N; i++)
    cin >> A[i];
  vector<int> sosuu;
  for (int i(2); i <= 1000000; i++) {
    if (isprime(i)) {
      sosuu.push_back(i);
    }
  }
  int k = int(sosuu.size());
  vector<int> used(k, 0);
  for (int i(0); i < N; i++) {
    for (int j(0); j < k; j++) {
      if (A[i] % sosuu[j] == 0) {
        used[j]++;
      }
    }
  }
  int maxi(0);
  for (int i(0); i < k; i++) {
    maxi = max(maxi, used[i]);
  }
  if (maxi <= 1)
    cout << "pairwise coprime" << endl;
  else if (maxi < N)
    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;
int c[1000005];

// n以下の整数について最小の素因数を求めた結果の配列を返す
// min_factor[i]はiを割り切る最小の数（iの素因数のうち最小のもの）
// min_factor[i] == iならiは素数（i=0, 1のときを除く）
vector<int> sieve(int n) {
  // 素数候補を管理する配列
  vector<int> min_factor(n + 1);
  // 2以上の数を一度素数候補に入れる
  for (int i = 0; i <= n; i++)
    min_factor[i] = i;
  // それぞれの数について最小の素因数を求める
  for (int i = 2; i * i <= n; i++) {
    if (min_factor[i] == i) {
      for (int j = 2; i * j <= n; j++) {
        if (min_factor[i * j] > i) {
          min_factor[i * j] = i;
        }
      }
    }
  }
  return min_factor;
}

// 配列min_factorを使ってmを素因数分解する
// 配列ansにはmの素因数が小さい順に格納される
vector<int> factor(vector<int> &min_factor, int m) {
  vector<int> ans;
  while (m > 1) {
    ans.push_back(min_factor[m]);
    m /= min_factor[m];
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  vector<int> min_factor = sieve(a[n - 1]);
  int flag = 0;
  for (int i = 0; i < n; i++) {
    vector<int> ans = factor(min_factor, a[i]);
    int pre = 1;
    for (auto u : ans) {
      if (u != pre)
        c[u]++;
      if (c[u] == n) {
        cout << "not coprime";
        return 0;
      }
      if (c[u] > 1)
        flag++;
      pre = u;
    }
  }
  if (flag == 0) {
    cout << "pairwise coprime";
    return 0;
  } else {
    cout << "setwise coprime";
    return 0;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int c[1000005];
int s[1000005];
long long int gcd(long long int x, long long int y) {
  long long int tmp;
  long long int r;
  if (x > y) {
    tmp = x;
    x = y;
    y = tmp;
  }
  r = y % x;
  while (r != 0) {
    y = x;
    x = r;
    r = y % x;
  }
  return x;
}
vector<bool> prime_table(int n) {
  vector<bool> prime(n + 1, true);
  if (n >= 0)
    prime[0] = false;
  if (n >= 1)
    prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (!prime[i])
      continue;
    for (int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
int main() {
  int n;
  cin >> n;
  int a[n];
  int MAX = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    MAX = max(MAX, a[i]);
  }
  auto t = prime_table(MAX);
  vector<int> prime;
  for (int i = 2; i <= MAX; i++)
    if (t[i] == true)
      prime.push_back(i);
  int flag = 0;
  for (int i = 0; i < n; i++) {
    for (auto u : prime) {
      if (u > a[i])
        break;
      else if (a[i] % u == 0)
        c[u]++;
      if (c[u] > 1) {
        flag++;
        break;
      }
    }
    if (flag > 0)
      break;
  }
  if (flag == 0) {
    cout << "pairwise coprime";
    return 0;
  }
  s[1] = gcd(a[0], a[1]);
  for (int i = 1; i < n - 1; i++)
    s[i + 1] = gcd(s[i], a[i + 1]);
  if (s[n - 1] > 1) {
    cout << "not coprime";
    return 0;
  } else {
    cout << "setwise coprime";
    return 0;
  }
}