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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read() {
  char ch = getchar();
  ll x = 0;
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x;
}

ll n, cnt;
ll a[2000010];
bool isnp[2000010];
ll tong[2000010];
ll p[2000010];

void init() {
  isnp[0] = isnp[1] = true;
  for (ll i = 2; i <= 1e6; i++) {
    if (!isnp[i])
      p[++cnt] = i;
    for (ll j = 1; j <= cnt && i * p[j] <= 1e6; j++) {
      isnp[i * p[j]] = true;
      if (i % p[j] == 0)
        break;
    }
  }
}

ll gcd(ll x, ll y) { return (!y ? x : gcd(y, x % y)); }

int main() {
  init();
  n = read();
  for (ll i = 1; i <= n; i++)
    a[i] = read(), tong[a[i]]++;
  bool flag = true;
  for (ll i = 1; i <= cnt; i++) {
    ll tot = 0;
    for (ll j = 1;; j++) {
      if (p[i] * j > 1e6)
        break;
      tot += tong[p[i] * j];
    }
    if (tot >= 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
    puts("pairwise coprime");
    return 0;
  }
  ll g = a[1];
  for (ll i = 2; i <= n; i++)
    g = gcd(g, a[i]);
  puts(g == 1 ? "setwise coprime" : "not coprime");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read() {
  char ch = getchar();
  ll x = 0;
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x;
}

ll n, cnt;
ll a[2000010];
bool isnp[2000010];
ll p[2000010];

void init() {
  isnp[0] = isnp[1] = true;
  for (ll i = 2; i <= 1e6; i++) {
    if (!isnp[i])
      p[++cnt] = i;
    for (ll j = 1; j <= cnt && i * p[j] <= 1e6; j++) {
      isnp[i * p[j]] = true;
      if (i % p[j] == 0)
        break;
    }
  }
}

ll gcd(ll x, ll y) { return (!y ? x : gcd(y, x % y)); }

int main() {
  init();
  n = read();
  for (ll i = 1; i <= n; i++)
    a[i] = read();
  bool flag = true;
  for (ll i = 1; i <= cnt; i++) {
    ll tot = 0;
    for (ll j = 1; j <= n; j++) {
      if (a[j] % p[i] == 0)
        tot++;
      if (tot >= 2)
        break;
    }
    if (tot >= 2) {
      flag = false;
      break;
    }
  }
  if (flag) {
    puts("pairwise coprime");
    return 0;
  }
  ll g = a[1];
  for (ll i = 2; i <= n; i++)
    g = gcd(g, a[i]);
  puts(g == 1 ? "setwise coprime" : "not coprime");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

int GCD(int x, int y) {
  if (x < y)
    swap(x, y);

  while (y > 0) {
    x = x % y;
    swap(x, y);
  }
  return x;
}

// 因数にint型の整数、出力はvector<int>型の素数配列
vector<int> Prime_Factorize(int N) {
  vector<int> out;
  while (N % 2 == 0) {
    N /= 2;
    out.push_back(2);
  }
  // 3以上の素数は全部奇数！！
  int Odds = 3;
  while (Odds * Odds <= N) {
    if (N % Odds == 0) {
      N /= Odds;
      out.push_back(Odds);
    } else {
      Odds += 2;
    }
  }
  if (N != 1)
    out.push_back(N);

  return out;
}

int main() {
  int N;
  cin >> N;

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

  sort(A.begin(), A.end());

  int sup = 1000000;
  int flag = 0;

  int table[sup];
  for (int i = 0; i < sup; ++i) {
    table[i] = 0;
  }

  for (int i = 0; i < N; ++i) {
    int num = A[i];
    vector<int> lst;
    lst = Prime_Factorize(num);
    for (int j = 0; j < lst.size(); ++j) {
      if (table[lst[j]] == 1)
        flag = 1;
    }
    for (int j = 0; j < lst.size(); ++j) {
      table[lst[j]] = 1;
    }
  }

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

  int gcd = A[0];
  for (int i = 1; i < N; ++i) {
    gcd = GCD(gcd, A[i]);
  }

  if (flag == 1) {
    if (gcd == 1) {
      cout << "setwise coprime" << endl;
    } else {
      cout << "not coprime" << endl;
    }
  }
}


Error: 1

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

int GCD(int x, int y) {
  if (x < y)
    swap(x, y);

  while (y > 0) {
    x = x % y;
    swap(x, y);
  }
  return x;
}

int main() {
  int N;
  cin >> N;

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

  sort(A.begin(), A.end());

  int sup = 1010;
  int flag = 0;

  int table[sup];
  for (int i = 0; i < sup; ++i) {
    table[i] = 0;
  }
  for (int i = 0; i < N; ++i) {
    int num = A[i];
    for (int j = 2; j < sup; ++j) {
      if (num == 1)
        break;
      if (num % j != 0)
        continue;

      while (num % j == 0) {
        num /= j;
        if (table[j] == 1)
          flag = 1;
      }
      table[j] = 1;
    }
    if (flag == 1)
      break;
  }

  for (int i = 1; i < N; ++i) {
    if (A[i] == A[i - 1]) {
      flag = 1;
      break;
    }
  }

  if (flag == 0) {
    cout << "pairwise coprime" << endl;
    exit(EXIT_FAILURE);
  }

  int gcd = A[0];
  for (int i = 1; i < N; ++i) {
    gcd = GCD(gcd, A[i]);
  }

  if (gcd == 1) {
    cout << "setwise coprime" << endl;
    exit(EXIT_FAILURE);
  }

  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;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
#define PI 3.14159265358979323846264338327950L
// setprecision(15)

#define MAX 1000000
int minf[MAX + 1];
int p[MAX + 1];

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

void sieve() {
  memset(minf, -1, sizeof(minf));
  for (int i = 2; i <= MAX; i++) {
    if (minf[i] != -1)
      continue;
    minf[i] = i;
    for (int j = i * 2; j <= MAX; j += i) {
      minf[j] = i;
    }
  }
}

int div(int n) {
  while (n != 1) {
    int d = minf[n];
    if (p[d] == 1)
      return 1;
    p[d] = 1;
    while (n % d == 0)
      n = n / d;
  }
  return 0;
}

int main() {
  sieve();
  memset(p, -1, sizeof(p));
  int N;
  cin >> N;
  int i;
  int pc_flg;
  vector<int> A(N);
  for (i = 0; i < N; i++)
    cin >> A[i];
  for (i = 0; i < N; i++) {
    int ret = div(A[i]);
    if (ret == 1)
      break;
  }
  if (i == N) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int r = A[0];
  for (int i = 1; i < N; i++) {
    r = gcd(r, A[i]);
  }
  if (r == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << 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;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
#define PI 3.14159265358979323846264338327950L
int gcd(int x, int y) {
  int r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}

int main() {
  int N;
  cin >> N;
  vector<int> v;
  rep(i, N) {
    int temp;
    cin >> temp;
    v.push_back(temp);
  }
  int ii, jj;
  for (ii = 0; ii < N; ii++) {
    for (jj = ii + 1; jj < N; jj++) {
      int ret = gcd(v[ii], v[jj]);
      if (ret != 1)
        break;
    }
    if (jj != N) {
      break;
    }
  }
  if (ii == N) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int tmp = v[0];
  for (int ii = 1; ii < N; ii++) {
    int ret = gcd(tmp, v[ii]);
    tmp = ret;
  }
  if (tmp == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
using Grid = vector<vector<char>>;
using vin = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vch = vector<char>;
using pinin = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i, n) for (ll i = 0; i < (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes = "Yes", no = "No";

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rell(i, n) cin >> a[i];
  ll max = 1000006;
  vll sub(max, max);
  rell(i, max) {
    if (i == 0)
      continue;
    else if (i == 1)
      sub[i] = 1;
    else if (sub[i] != max)
      continue;
    else {
      sub[i] = i;
      for (ll j = 1; i * j <= max; j++) {
        if (sub[i] != max)
          sub[i * j] = i;
      }
    }
  }

  set<ll> div;
  bool pa = true;
  rell(i, n) {
    ll j = a[i];
    set<ll> divin;
    while (j != 1) {

      divin.insert(sub[j]);
      j /= sub[j];
    }
    for (auto value : divin) {
      if (div.count(value))
        pa = false;
      else
        div.insert(value);
    }
    if (!pa) {
      break;
    }
  }
  if (pa) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll gc = a[0];
  rell(i, n) { gc = gcd(gc, a[i]); }
  if (gc == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
using Grid = vector<vector<char>>;
using vin = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vch = vector<char>;
using pinin = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

int main() {

  int n;
  cin >> n;
  vin a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a);
  rese(a);
  int gc = a[0];
  rep(i, n) {
    bool owa = false;
    rep(j, i) {
      if (__gcd(a[i], a[j]) != 1) {
        owa = true;
        break;
      }
    }
    if (owa) {
      break;
    }
    if (i == n - 1) {
      cout << "pairwise coprime" << endl;
      return 0;
    }
  }
  rep(i, n) {
    gc = __gcd(a[i], gc);
    if (gc == 1) {
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) {
  ll n = vec.size();
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
}

void pr2d(vector<vector<ll>> vvec) {
  ll h = vvec.size();
  ll w = vvec.at(0).size();
  rep(i, h) {
    rep(j, w) { cout << vvec.at(i).at(j) << " "; }
    cout << "\\n";
  }
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(1000001, 1);
  a.at(0) = 0;
  a.at(1) = 0;
  for (int i = 2; i <= 1000; i++) {
    if (!a.at(i))
      continue;
    ll x = i;
    while (true) {
      x += i;
      if (x > 1e6)
        break;
      a.at(x) = 0;
    }
  }

  vector<ll> b(1000001, 0);
  rep(i, n) {
    ll x;
    cin >> x;
    b.at(x)++;
  }
  bool pairwise = 1;
  bool setwise = 1;

  rep(i, 1000001) {
    if (!a.at(i))
      continue;
    ll cnt = 0;
    ll x = i;
    while (x <= 1e6) {
      if (b.at(x))
        cnt += b.at(x);
      x += i;
    }
    if (cnt > 1)
      pairwise = 0;
    if (cnt == n) {
      pairwise = 0, setwise = 0;
      break;
    }
    // cout << i << " " << cnt << endl;
  }
  // cout << setwise << endl;
  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>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) {
  ll n = vec.size();
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
}

void pr2d(vector<vector<ll>> vvec) {
  ll h = vvec.size();
  ll w = vvec.at(0).size();
  rep(i, h) {
    rep(j, w) { cout << vvec.at(i).at(j) << " "; }
    cout << "\\n";
  }
}

int main() {
  ll n;
  cin >> n;
  vector<bool> a(1001, 1);
  a.at(0) = 0, a.at(1) = 0;
  for (int i = 0; i <= 1000; i++) {
    if (!a.at(i))
      continue;
    ll x = i;
    while (true) {
      x += i;
      if (x > 1000)
        break;
      a.at(x) = 0;
    }
  }
  // rep(i,1001) cout << a.at(i);
  vector<ll> b(0);
  rep(i, 1001) {
    if (a.at(i))
      b.push_back(i);
  }
  ll sz = b.size();
  vector<ll> cnt(sz, 0);
  rep(i, n) {
    ll x;
    cin >> x;
    sz = b.size();
    rep(j, sz) {
      if (!(x % b.at(j))) {
        cnt.at(j)++;
      }
      while (!(x % b.at(j))) {
        x /= b.at(j);
      }
    }
    if (x != 1) {
      b.push_back(x);
      cnt.push_back(1);
    }
  }
  // prvec(b);
  // prvec(cnt);

  ll mxm = 0;
  for (auto z : cnt) {
    mxm = max(mxm, z);
  }
  if (mxm == n) {
    cout << "not coprime" << endl;
  } else if (mxm >= 2) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "pairwise coprime" << endl;
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

// abc177_e.cpp
// Sat Aug 29 20:53:45 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;

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

  int p = 0;
  vector<int> is_prime(2100, 1);
  vector<int> prime;
  for (int i = 2; i <= 2000; i++) {
    if (is_prime[i]) {
      prime.push_back(i);
      for (int j = 2 * i; j <= 2000; j += i) {
        is_prime[j] = 0;
      }
    }
  }

  vector<int> insu(1000000, 0);
  rep(i, n) {
    int temp = a[i];
    rep(j, prime.size()) {
      int x = prime[j];
      if (a[i] < x * x)
        break;
      if (temp % x == 0) {
        insu[x]++;
        temp = temp / x;
        while (temp % x == 0) {
          temp = temp / x;
        }
      }
    }
    insu[temp]++; // 最後の割り算の余りの処理を忘れない
  }

  int pairflag = 1;
  int setflag = 1;
  for (int i = 2; i < 1000000; i++) {
    if (insu[i] != 0) {
      if (insu[i] != 1) {
        pairflag = 0;
      }
      if (insu[i] == n) {
        setflag = 0;
      }
    }
  }

  // rep(i,10){
  // 	cout << i << " " << insu[i] << endl;
  // }

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

Error: TLE

Fixed submission:

// abc177_e.cpp
// Sat Aug 29 20:53:45 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;

  int a[n];
  rep(i, n) cin >> a[i];

  vector<int> insu(1000000, 0);
  rep(i, n) {
    int x = 2;
    int temp = a[i];
    while (a[i] >= x * x) { // iの素因数分解ここから
      if (temp % x == 0) {
        insu[x]++;
        temp = temp / x;
        while (temp % x == 0) {
          temp = temp / x;
        }
      }
      x++;
    }
    insu[temp]++; // 最後の割り算の余りの処理を忘れない
  }

  int pairflag = 1;
  int setflag = 1;
  for (int i = 2; i < 1000000; i++) {
    if (insu[i] != 0) {
      if (insu[i] != 1) {
        pairflag = 0;
      }
      if (insu[i] == n) {
        setflag = 0;
      }
    }
  }

  // rep(i,10){
  // 	cout << i << " " << insu[i] << endl;
  // }

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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod = 1000000007;
const char nl = '\\n';

ll mp[1000010] = {0};

void solve() {
  ll i, j, k, l, m, n, u, v, x, y;
  cin >> n;
  vector<ll> vc(n);
  ll gcd;
  cin >> gcd;
  mp[gcd]++;
  vc[0] = gcd;
  for (i = 1; i < n; i++) {
    cin >> vc[i];
    mp[vc[i]]++;
    gcd = __gcd(gcd, vc[i]);
  }
  if (gcd != 1) {
    cout << "not coprime" << nl;
    return;
  }

  for (i = 2; i <= 1000000; i++) {
    if (mp[i] > 1) {
      cout << "setwise coprime" << nl;
      return;
    }
  }

  for (i = 0; i < n; i++) {
    x = vc[i];
    for (j = 2; j * j < x; j++) {
      if (x % j == 0) {
        mp[j]++;
        mp[x / j]++;
        if (mp[j] > 1 || mp[x / j] > 1) {
          cout << "setwise coprime" << nl;
          return;
        }
      }
    }
    if (j * j == x) {
      mp[j]++;
      if (mp[j] > 1 || mp[x / j] > 1) {
        cout << "setwise coprime" << nl;
        return;
      }
    }
  }
  cout << "pairwise coprime" << nl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1, i = 1;
  //    cin >> t;
  while (t--) {
    //	    cout<<"Case #"<< i++ <<": ";
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod = 1000000007;
const char nl = '\\n';

ll mp[1000010] = {0};

void solve() {
  ll i, j, k, l, m, n, u, v, x, y;
  cin >> n;
  vector<ll> vc(n);
  ll gcd;
  cin >> gcd;
  mp[gcd]++;
  vc[0] = gcd;
  for (i = 1; i < n; i++) {
    cin >> vc[i];
    mp[vc[i]]++;
    gcd = __gcd(gcd, vc[i]);
  }
  if (gcd != 1) {
    cout << "not coprime" << nl;
    return;
  }

  for (i = 2; i <= 1000000; i++) {
    if (mp[i] > 1) {
      cout << "setwise coprime" << nl;
      return;
    }
  }

  for (i = 0; i < n; i++) {
    x = vc[i];
    for (j = 2; j * j < x; j++) {
      if (x % j == 0) {
        mp[j]++;
        mp[x / j]++;
      }
    }
    if (j * j == x)
      mp[j]++;
  }

  for (i = 0; i < n; i++) {
    x = vc[i];
    for (j = 2; j * j <= x; j++) {
      if (x % j == 0 && (mp[x / j] > 1 || mp[j] > 1)) {
        cout << "setwise coprime" << nl;
        return;
      }
    }
  }
  cout << "pairwise coprime" << nl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1, i = 1;
  //    cin >> t;
  while (t--) {
    //	    cout<<"Case #"<< i++ <<": ";
    solve();
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
const int maxn = 2000001;
int c[maxn], mark[maxn];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  int n;
  cin >> n;
  assert(n >= 2);
  int a[n];
  memset(c, 0, sizeof c);
  bool not_pairwise = false;
  vector<int> v;

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

  for (int i = 0; i < n; i++) {
    c[v[i]]++;
  }

  int g = 1;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      g = v[0];
    else
      g = __gcd(v[i], g);
  }
  memset(mark, 0, sizeof mark);
  if (!not_pairwise) {

    for (int i = 2; i < maxn; i++) {
      if (mark[i])
        continue;
      int cnt = 0;
      for (int j = i; j < maxn; j += i) {
        if (c[j])
          cnt += c[j];
        mark[j] = 1;
      }
      if (cnt > 1) {
        not_pairwise = true;
      }
    }
  }
  string ans = "";
  if (!not_pairwise) {
    ans = "pairwise coprime\\n";
  } else {
    if (g == 1) {
      ans = "setwise coprime\\n";
    } else
      ans = "not coprime\\n";
  }
  // if(n==1)
  // 	ans=="not coprime\\n";

  cout << ans << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 2000001;
int c[maxn], mark[maxn];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  int n;
  cin >> n;
  assert(n >= 2);
  int a[n];
  memset(c, 0, sizeof c);
  bool not_pairwise = false;
  vector<int> v;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != 1)
      v.push_back(a[i]);
  }

  n = v.size();
  if (n <= 0) {
    cout << "pairwise coprime\\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    c[v[i]]++;
    // if(c[v[i]] > 1) not_pairwise = true;
  }

  int g = 1;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      g = v[0];
    else
      g = gcd(v[i], g);
  }

  if (!not_pairwise) {
    memset(mark, 0, sizeof mark);
    for (int i = 2; i < maxn; i++) {
      if (mark[i])
        continue;
      int cnt = 0;
      for (int j = i; j < maxn; j += i) {
        if (c[j])
          cnt += c[j];
        mark[j] = 1;
      }
      if (cnt > 1) {
        not_pairwise = true;
      }
    }
  }
  string ans = "";
  if (!not_pairwise) {
    ans = "pairwise coprime\\n";
  } else {
    if (g == 1) {
      ans = "setwise coprime\\n";
    } else
      ans = "not coprime\\n";
  }
  if (n == 1)
    assert(ans == "setwise coprime\\n");

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 10000000000

int gcd(int a, int b) {
  while (a % b != 0) {
    int tmp = a % b;
    a = b;
    b = tmp;
  }
  return b;
}

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

  vector<int> count(1000005, 0);
  for (int i = 0; i < N; i++) {
    int a = A[i];
    for (int j = 2; j * j <= a; j++) {
      if (a % j == 0) {
        count[j]++;
        while (a % j == 0) {
          a /= j;
        }
      }
    }
    if (a > 1) {
      count[a]++;
    }
  }

  bool flag = true;
  for (int i = 0; i <= 1000000; i++) {
    if (count[i] > 1) {
      flag = false;
    }
  }

  if (flag) {
    cout << "pairwise coprime" << endl;
  } else {
    int a = A[0];
    for (int i = 1; i < N; i++) {
      a = gcd(a, A[i]);
    }

    if (a == 1) {
      cout << "setwise coprime" << endl;
    } else {
      cout << "not coprime" << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 10000000000

#define MAX 1000000
vector<int> p;
vector<bool> p_table(MAX + 1, true);
void prime() {
  p_table.at(0) = false, p_table.at(1) = false;
  for (int i = 2; i <= MAX; i++) {
    if (p_table.at(i)) {
      p.push_back(i);
      for (int j = 2; i * j <= MAX; j++) {
        p_table.at(i * j) = false;
      }
    }
  }
}

int gcd(int a, int b) {
  while (a % b != 0) {
    int tmp = a % b;
    a = b;
    b = tmp;
  }
  return b;
}

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

  prime();
  int n = p.size();
  vector<int> count(n, 0);
  for (int i = 0; i < N; i++) {
    int a = A[i];
    int j = 0;
    while (a > 1) {
      if (a % p[j] == 0) {
        count[j]++;
        while (a % p[j] == 0) {
          a /= p[j];
        }
      }
      j++;
    }
  }

  bool flag = true;
  for (int i = 0; i < n; i++) {
    if (count[i] > 1) {
      flag = false;
    }
  }

  if (flag) {
    cout << "pairwise coprime" << endl;
  } else {
    int a = A[0];
    for (int i = 1; i < N; i++) {
      a = gcd(a, A[i]);
    }

    if (a == 1) {
      cout << "setwise coprime" << endl;
    } else {
      cout << "not coprime" << endl;
    }
  }
}