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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<ll> prime_factorize(ll N) {
  vector<ll> res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    while (N % a == 0) {
      N /= a;
    }
    res.push_back(a);
  }

  if (N != 1)
    res.push_back(N);
  return res;
}

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

  set<int> pairwise;
  vector<int> setwise(1000000 + 1, 0);
  vector<ll> v0 = prime_factorize(A[0]);
  for (auto i : v0) {
    pairwise.insert(i);
    setwise[i]++;
  }

  bool is_pairwise = true;
  for (int i = 1; i < N; i++) {
    vector<ll> v = prime_factorize(A[i]);
    for (auto j : v) {
      // check pairwise
      if (is_pairwise) {
        if (pairwise.count(j) == 0)
          pairwise.insert(j);
        else
          is_pairwise = false;
      }
      // check setwise
      setwise[j]++;
    }
  }
  bool is_setwise = true;
  for (auto i : setwise) {
    if (i == N)
      is_setwise = false;
  }

  if (is_pairwise)
    cout << "pairwise coprime" << endl;
  else if (is_setwise)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<ll> prime_factorize(ll N) {
  vector<ll> res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    while (N % a == 0) {
      N /= a;
    }
    res.push_back(a);
  }

  if (N != 1)
    res.push_back(N);
  return res;
}

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

  set<int> pairwise;
  map<int, int> setwise;
  vector<ll> v0 = prime_factorize(A[0]);
  for (auto i : v0) {
    pairwise.insert(i);
    setwise[i]++;
  }

  bool is_pairwise = true;
  for (int i = 1; i < N; i++) {
    vector<ll> v = prime_factorize(A[i]);
    for (auto j : v) {
      // check pairwise
      if (is_pairwise) {
        if (pairwise.count(j) == 0)
          pairwise.insert(j);
        else
          is_pairwise = false;
      }
      // check setwise
      setwise[j]++;
    }
  }
  bool is_setwise = true;
  for (auto i : setwise) {
    if (i.second == N)
      is_setwise = false;
  }

  if (is_pairwise)
    cout << "pairwise coprime" << endl;
  else if (is_setwise)
    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 INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

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

vi T;
void makeTable() {
  vi prime(1e6 + 1, 1);
  prime[2] = prime[3] = 1;
  for (int i = 2; i <= 1e6; i++) {
    if (prime[i])
      T.pb(i);
    for (int j = 0; j < T.size() && i * T[j] <= 1e6; j++) {
      prime[i * T[j]] = 0;
      if (i % T[j] == 0)
        break;
    }
  }
}

int main() {
  fastIO;
  int n, m;
  cin >> n;
  vi vis(1e6 + 5, 0);
  for (int i = 0; i < n; i++)
    cin >> m, vis[m]++;

  makeTable();
  bool flag = true;
  for (auto x : T) {
    int cnt = 0;
    for (int i = x; i <= 1e6; i += x)
      cnt += vis[i];

    if (cnt > 1)
      flag = false;
    if (cnt == n) {
      cout << "not coprime" << endl;
      return 0;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

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

int main() {
  fastIO;
  int n;
  cin >> n;
  vi a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  bool flag = true;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      if (gcd(a[i], a[j]) > 1) {
        flag = false;
        break;
      }

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

  int temp = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++)
    temp = gcd(temp, a[i]);

  if (temp == 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;
typedef long long ll;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
const double EPS = 1e-9;
const double PI = acos(-1);
const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2},  {1, 2},
                             {2, -1},  {2, 1},  {-1, -2}, {1, -2}};
// const int dx[]={0,0,0,1,1,1,-1,-1,-1};
// const int dy[]={-1,0,1,-1,0,1,-1,0,1};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
// #define MOD         1000000007LL
#define MAX 1000005
const ll MOD = 1000000000 + 7;
int arr[MAX], n;
int fact[MAX];

bool pairwise() {

  for (int i = 0; i < n; i++) {
    int x = arr[i];
    for (int j = 1; j * j <= x; j++) {
      if (x % j == 0) {
        fact[j]++;
        if (j > 1 && fact[j] >= 2)
          return false;
        if (x / j != j) {
          fact[x / j]++;
          if (fact[x / j] >= 2)
            return false;
        }
      }
    }
  }

  return true;
}

bool setwise() {
  int ans = arr[0];

  for (int i = 1; i < n; i++) {
    ans = __gcd(ans, arr[i]);
  }
  if (ans != 1)
    return false;
  return true;
}

int main() {
  FAST int t;
  t = 1;

  while (t--) {

    cin >> n;

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

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


Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
const double EPS = 1e-9;
const double PI = acos(-1);
const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2},  {1, 2},
                             {2, -1},  {2, 1},  {-1, -2}, {1, -2}};
// const int dx[]={0,0,0,1,1,1,-1,-1,-1};
// const int dy[]={-1,0,1,-1,0,1,-1,0,1};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
// #define MOD         1000000007LL
#define MAX 1000005
const ll MOD = 1000000000 + 7;
int arr[MAX], n;
int fact[MAX];

bool pairwise() {

  for (int i = 0; i < n; i++) {
    int x = arr[i];
    for (int j = 1; j * j <= x; j++) {
      if (x % j == 0) {
        if (x / j == j)
          fact[j]++;
        else {
          fact[x / j]++;
          fact[j]++;
        }
      }
    }
  }

  for (int i = 2; i < MAX; i++)
    if (fact[i] >= 2)
      return false;
  return true;
}

bool setwise() {
  int ans = arr[0];

  for (int i = 1; i < n; i++) {
    ans = __gcd(ans, arr[i]);
  }
  if (ans != 1)
    return false;
  return true;
}

int main() {
  FAST int t;
  t = 1;

  while (t--) {

    cin >> n;

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

    if (pairwise())
      cout << "pairwise coprime\\n";
    else if (setwise())
      cout << "setwise coprime\\n";
    else
      cout << "not coprime\\n";
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

//----------BHAVIK DIWANI(PICT_COMP)---------------
#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mod 1000000007
#define int long long
#define pb push_back
#define mkp make_pair
#define endl '\\n'
#define mii map<int, int>
using namespace std;
const int MAX = 1e6 + 3;
int mp[MAX] = {0}, hcf;
int solve() {
  int n;
  cin >> n;
  int a[n];
  int hcf = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int i = 0; i < MAX; i++) {
    if (mp[i])
      hcf = __gcd(hcf, i);
  }
  if (hcf > 1) {
    cout << "not coprime";
    return 0;
  }
  for (int i = 2; i < MAX; i++) {
    int cnt = 0;
    for (int j = i; j < MAX; j += i) {
      if (mp[j])
        cnt++;
      if (cnt > 1) {
        cout << "setwise coprime";
        return 0;
      }
    }
    if (cnt > 1) {
      cout << "setwise coprime";
      return 0;
    }
  }
  cout << "pairwise coprime";
  return 0;
}
signed main() {
  fastio;
  solve();
}


Error: TLE

Fixed submission:

//----------BHAVIK DIWANI(PICT_COMP)---------------
#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define MAX 1000002
#define pb push_back
#define mkp make_pair
#define endl '\\n'
#define mii map<int, int>
int gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
using namespace std;
int solve() {
  int n;
  cin >> n;
  int a[n];
  int hcf = 0;
  mii mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int i = 0; i < MAX; i++) {
    if (mp[i])
      hcf = gcd(hcf, i);
  }
  if (hcf > 1) {
    cout << "not coprime";
    return 0;
  }
  for (int i = 2; i < 1000; i++) {
    int cnt = 0;
    for (int j = i; j < MAX; j += i) {
      if (mp[j])
        cnt++;
      if (cnt > 1) {
        cout << "setwise coprime";
        return 0;
      }
    }
    if (cnt > 1) {
      cout << "setwise coprime";
      return 0;
    }
  }
  cout << "pairwise coprime";
  return 0;
}
signed main() {
  fastio;
  solve();
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

using ll = long long;
using P = pair<int, int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1 << 30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll gcd(ll x, ll y) {
  if (x % y == 0) {
    return y;
  }

  else {
    return gcd(y, x % y);
  }
}

int main() {
  ll N;
  cin >> N;
  vector<ll> v(N);
  rep(i, N) cin >> v[i];
  vector<bool> prime(1000005, true);
  prime[0] = prime[1] = false;
  vector<ll> m(1000005, 0);
  vector<ll> cnt(1000005, 0);
  rep(i, N) cnt[v[i]]++;
  rep(i, 1000005) {
    if (prime[i]) {
      m[i] += cnt[i];
      for (ll j = 2LL; i * j < 1000005; j++) {
        prime[i * j] = false;
        m[i] += cnt[i * j];
      }
    }
  }
  bool ok1 = true;
  rep(i, 1000005) {
    if (m[i] >= 2)
      ok1 = false;
  }
  ll g = v[0];
  rep(i, N - 1) {
    g = gcd(g, v[i + 1]);
    if (g == 1)
      break;
  }
  if (ok1)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

Error: TLE

Fixed submission:

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

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

using ll = long long;
using P = pair<int, int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1 << 30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll gcd(ll x, ll y) {
  if (x % y == 0) {
    return y;
  }

  else {
    return gcd(y, x % y);
  }
}

int main() {
  ll N;
  cin >> N;
  vector<ll> v(N);
  rep(i, N) cin >> v[i];
  vector<bool> prime(1000005, true);
  prime[0] = prime[1] = false;
  rep(i, 1000005) {
    if (prime[i]) {
      for (ll j = 2LL; i * j < 1000005; j++)
        prime[i * j] = false;
    }
  }
  vector<ll> P;
  rep(i, 1000005) {
    if (prime[i])
      P.push_back(i);
  }
  map<ll, ll> m;
  rep(i, N) {
    ll t = v[i];
    for (ll j = 0; P[j] * P[j] <= v[i]; j++) {
      if (t % P[j] == 0)
        m[P[j]]++;
      while (t % P[j] == 0) {
        t /= P[j];
      }
    }
    if (t != 1)
      m[t]++;
  }
  bool ok1 = true;
  for (auto x : m) {
    if (x.second >= 2)
      ok1 = false;
  }
  ll g = v[0];
  rep(i, N - 1) { g = gcd(g, v[i + 1]); }
  if (ok1)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not 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 namespace std;
using ll = long long;
constexpr ll mod = 1000000007;
constexpr int inf = 1000000000;
constexpr ll linf = 1000000000000000000;

int main() {
  int n;
  scanf("%d", &n);
  map<int, int> mp;
  bool flag1 = true;
  bool flag2 = true;
  rep(k, n) {
    int a;
    scanf("%d", &a);
    for (int i = 2; i * i <= a; ++i) {
      if (a % i != 0)
        continue;
      while (a % i == 0) {
        a /= i;
      }
      if (mp[i] > 0)
        flag1 = false;
      ++mp[i];
    }
    if (a != 1) {
      if (mp[a] > 0)
        flag1 = false;
      ++mp[a];
    }
  }
  if (flag1) {
    cout << "pairwise coprime\\n";
  } else {
    for (auto e : mp) {
      if (e.second == n)
        flag2 = false;
    }
    if (flag2)
      cout << "setwise coprime\\n" << endl;
    else
      cout << "not coprime\\n" << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
constexpr ll mod = 1000000007;
constexpr int inf = 1000000000;
constexpr ll linf = 1000000000000000000;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  bool flag1 = true;
  bool flag2 = true;
  rep(k, n) {
    int a;
    cin >> a;
    for (ll i = 2; i * i <= a; ++i) {
      if (a % i != 0)
        continue;
      while (a % i == 0) {
        a /= i;
      }
      if (mp[i] > 0)
        flag1 = false;
      ++mp[i];
    }
    if (a != 1) {
      if (mp[a] > 0)
        flag1 = false;
      ++mp[a];
    }
  }
  if (flag1) {
    cout << "pairwise coprime" << endl;
  } else {
    for (auto e : mp) {
      if (e.second == n)
        flag2 = false;
    }
    if (flag2)
      cout << "setwise coprime" << endl;
    else
      cout << "not coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
int n, a[MAXN];
unordered_map<int, int> mp;
// map<int,int>mp;
// TLE了 可能思路：每个数*一个数的形式 判断所得的num 然后与n比较
int main() {
  scanf("%d", &n);
  int ans = 0, max1 = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mp[a[i]]++, max1 = max(max1, a[i]);
  for (int i = 2; i <= 1000000; i++) {
    int num = 0;
    for (int j = i; j <= 1000000; j += i) {
      num += mp[j];
    }
    ans = max(num, ans);
  }
  if (ans == 1 || mp[1] == n)
    printf("pairwise coprime\\n");
  else if (ans < n)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
  return 0;
}

Error: TLE

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
int n, a[MAXN];
map<int, int> mp;
// TLE了 可能思路：每个数*一个数的形式 判断所得的num 然后与n比较
int main() {
  scanf("%d", &n);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mp[a[i]]++;
  for (int i = 2; i <= 1000000; i++) {
    int num = 0;
    for (int j = i; j <= 1000000; j += i) {
      if (mp[j]) {
        num += mp[j];
      }
    }
    ans = max(num, ans);
  }
  if (ans == 1)
    printf("pairwise coprime\\n");
  else if (ans < n)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
int n, a[MAXN];
unordered_map<int, int> mp;
// map<int,int>mp;
// TLE了 可能思路：每个数*一个数的形式 判断所得的num 然后与n比较
int main() {
  scanf("%d", &n);
  int ans = 0, max1 = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mp[a[i]]++, max1 = max(max1, a[i]);
  for (int i = 2; i <= max1; i++) {
    int num = 0;
    for (int j = i; j <= max1; j += i) {
      num += mp[j];
    }
    ans = max(num, ans);
  }
  if (ans <= 1)
    printf("pairwise coprime\\n");
  else if (ans < n)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
int n, a[MAXN];
// unordered_map<int,int>mp;
map<int, int> mp;
// TLE了 可能思路：每个数*一个数的形式 判断所得的num 然后与n比较
int main() {
  scanf("%d", &n);
  int ans = 0, max1 = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mp[a[i]]++, max1 = max(max1, a[i]);
  for (int i = 2; i <= 1000000; i++) {
    int num = 0;
    for (int j = i; j <= 1000000; j += i) {
      num += mp[j];
    }
    ans = max(num, ans);
  }
  if (ans == 1 || mp[1] == n)
    printf("pairwise coprime\\n");
  else if (ans < n)
    printf("setwise coprime\\n");
  else
    printf("not coprime\\n");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
const int MAX = 1e6 + 7;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
vector<int> a(MAX, 0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, gcd, x;
  cin >> n;
  cin >> x;
  gcd = x;
  a[x]++;
  for (int i = 1; i < n; i++) {
    cin >> x;
    a[x]++;
    gcd = __gcd(gcd, x);
  }
  if (gcd > 1) {
    cout << "not coprime";
    return 0;
  }
  for (int i = 2; i < MAX; i++) {
    for (int j = i, f = 0; j < MAX; j += i) {
      if (a[j]) {
        if (f == 1) {
          cout << "setwise coprime";
          return 0;
        } else
          f = 1;
      }
    }
  }
  cout << "pairwise coprime";
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
const int MAX = 1e6 + 7;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
set<int> p;
vector<int> a(MAX, 0), ans(MAX, 0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    int t = a[i];
    for (int j = 2; j <= t; j++) {
      if (a[i] % j == 0) {
        p.insert(j);
        ans[j]++;
        a[i] /= j;
        while (a[i] % j == 0)
          a[i] /= j;
      }
      if (a[i] == 1)
        break;
    }
  }
  int f = 0;
  for (auto i : p)
    if (ans[i] == n) {
      cout << "not coprime";
      return 0;
    }
  for (auto i : p)
    if (ans[i] != 1) {
      cout << "setwise coprime";
      return 0;
    }
  cout << "pairwise coprime";
  return 0;
}