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

#include <bits/stdc++.h>

using namespace 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;
}

void factorize(long long n, vector<int> &prime_cnt, vector<int> &min_factor) {
  int p;
  while (n > 1) {
    p = min_factor[n];
    n /= p;
    if (min_factor[n] != p) {
      prime_cnt[p]++;
    }
  }
}

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

  vector<int> A(N);

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

  vector<int> prime_cnt;
  vector<int> prime_list = sieve(1e6 + 1);

  prime_cnt.assign(1e6, 0);

  for (int i = 0; i < N; i++) {
    if (A[i] != 1) {
      factorize(A[i], prime_cnt, prime_list);
    }
  }

  bool pw_cp = true;
  bool st_cp = true;

  for (auto val : prime_cnt) {
    if (val == 0)
      continue;
    if (val != 1) {
      pw_cp = false;
    }
    if (val == N) {
      st_cp = false;
    }
  }

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

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace 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;
}

void factorize(long long n, vector<int> &prime_cnt, vector<int> &min_factor) {
  int p;
  while (n > 1) {
    p = min_factor[n];
    n /= p;
    if (min_factor[n] != p) {
      prime_cnt[p]++;
    }
  }
}

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

  vector<int> A(N);

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

  vector<int> prime_cnt;
  vector<int> prime_list = sieve(1e6);

  prime_cnt.assign(1e6, 0);

  for (int i = 0; i < N; i++) {
    if (A[i] != 1) {
      factorize(A[i], prime_cnt, prime_list);
    }
  }

  bool pw_cp = true;
  bool st_cp = true;

  for (auto val : prime_cnt) {
    if (val == 0)
      continue;
    if (val != 1) {
      pw_cp = false;
    }
    if (val == N) {
      st_cp = false;
    }
  }

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

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  lvector div(1000001, 0);
  rep(i, n) {
    ll tmp = A[i];
    if (tmp % 2 == 0) {
      div[2]++;
      while (tmp % 2 == 0)
        tmp /= 2;
    }
    for (ll d = 3; d * d <= tmp; d += 2)
      if (tmp % d == 0) {
        div[d]++;
        while (tmp % d == 0)
          tmp /= d;
      }
    if (tmp > 1)
      div[tmp]++;
  }
  ll m = *max_element(ALL(div));
  if (m < 2)
    print("pairwise coprime");
  else if (m < n)
    print("setwise coprime");
  else
    print("not coprime");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  lvector A(n);
  rep(i, n) cin >> A[i];
  lvector div(1000001, 0);
  ll val = __gcd(A[0], A[1]);
  rep(i, n) {
    ll tmp = A[i];
    if (A[i] % 2 == 0) {
      div[2]++;
      while (tmp % 2 == 0)
        tmp /= 2;
    }
    for (ll d = 3; d * d <= A[i]; d += 2) {
      if (tmp % d == 0)
        div[d]++;
      while (tmp % d == 0)
        tmp /= d;
    }
    if (tmp > 1)
      div[tmp]++;
    if (i >= 2)
      val = __gcd(val, A[i]);
  }
  ll m = *max_element(ALL(div));
  if (m < 2)
    print("pairwise coprime");
  else {
    if (val == 1)
      print("setwise coprime");
    else
      print("not coprime");
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  ll all;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i == 0)
      all = a[i];
    else
      all = gcd(all, a[i]);
  }

  unordered_set<int> seen;
  bool pc = true;
  for (int i = 0; i < n; ++i) {
    int tmp = a[i];
    for (int j = 2; j * j <= tmp; ++j) {
      if (tmp > 1 && tmp % j == 0 && seen.count(j)) {
        pc = false;
        break;
      }
      while (tmp > 1 && tmp % j == 0) {
        seen.insert(j);
        tmp /= j;
      }
    }
    if (tmp > 1 && seen.count(tmp))
      pc = false;
    else if (tmp > 1)
      seen.insert(tmp);
    if (!pc)
      break;
  }

  if (pc)
    puts("pairwise coprime");
  else if (all == 1ll)
    puts("setwise coprime");
  else
    puts("not coprime");
}


Error: TLE

Fixed submission:

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  map<ll, ll> counter;
  ll all;
  bool pc = true;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ll tmp = a[i];
    for (int j = 2; j * j <= tmp; ++j) {
      ll bfr = counter[j];
      while (tmp > 1 && tmp % j == 0) {
        tmp /= j;
        counter[j]++;
      }
      if (bfr != 0 && bfr != counter[j])
        pc = false;
    }
    if (tmp > 1) {
      if (counter[tmp] > 0)
        pc = false;
      counter[tmp]++;
    }
    if (i == 0)
      all = a[i];
    else
      all = gcd(all, a[i]);
  }
  if (pc)
    puts("pairwise coprime");
  else if (all == 1ll)
    puts("setwise coprime");
  else
    puts("not coprime");
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000050;
int a[MAXN], vis[MAXN], avis[MAXN];
vector<int> p;
bool get_prime(int maxx) {
  for (int i = 2; i <= maxx; i++) {
    if (vis[i])
      continue;
    vis[i] = 1;
    p.push_back(i);
    for (int j = 1; j * i <= maxx; j++) {
      if (avis[i * j] == 1) {
        if (vis[i] == 2)
          return 0;
        vis[i] = 2;
        if (j != 1)
          vis[i * j] = 1;
      } else if (avis[i * j] != 0)
        return 0;
      else
        vis[i * j] = 1;
    }
  }
  return 1;
}
int gcd(int t, int b) {
  if (t < b)
    swap(t, b);
  if (t % b == 0)
    return b;
  else
    return gcd(b, t % b);
}
void solve(int T) {
  int n, maxx = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxx = max(maxx, a[i]);
    avis[a[i]]++;
  }
  int gcdd = a[1];
  for (int i = 2; i <= n; i++) {
    gcdd = gcd(a[i], gcdd);
  }
  if (get_prime(maxx)) {
    puts("pairwise coprime");
  } else if (gcdd == 1) {
    puts("setwise coprime");
  } else {
    puts("not coprime");
  }
}
signed main() {
  int t = 1;
  // scanf("%d",&t);
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
const int INF = 0x3f3f3f3f;
const int MAXN = 200050;
int a[MAXN], vis[MAXN], avis[MAXN];
vector<int> p;
bool get_prime(int maxx) {
  for (int i = 2; i <= maxx; i++) {
    if (vis[i])
      continue;
    vis[i] = 1;
    p.push_back(i);
    for (int j = 2; j * i <= maxx; j++) {
      if (avis[i * j]) {
        if (vis[i] == 2)
          return 0;
        vis[i] = 2;
      }
      vis[i * j] = 1;
    }
  }
  return 1;
}
int gcd(int t, int b) {
  if (t < b)
    swap(t, b);
  if (t % b == 0)
    return b;
  else
    return gcd(b, t % b);
}
void solve(int T) {
  int n, maxx = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxx = max(maxx, a[i]);
    avis[a[i]] = 1;
  }
  int gcdd = a[1];
  for (int i = 2; i <= n; i++) {
    gcdd = gcd(a[i], gcdd);
  }
  if (get_prime(maxx)) {
    puts("pairwise coprime");
  } else if (gcdd == 1) {
    puts("setwise coprime");
  } else {
    puts("not coprime");
  }
}
signed main() {
  int t = 1;
  // scanf("%d",&t);
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

const int N = 1e6 + 5;

unordered_map<int, int> prcnt;
int lp[N], n, vvod, pair_copr, set_copr;
vector<int> pr, lispr, mas;

void fact(int chis) {
  if (chis <= 1) {
    return;
  }

  lispr.push_back(lp[chis]);

  fact(chis / lp[chis]);
}

int main() {
  ios_base::sync_with_stdio(0);
  // freopen( "input.txt", "r", stdin );

  for (int i = 2; i <= N; i++) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }

    for (int j = 0; j < int(pr.size()) && pr[j] <= lp[i] && i * pr[j] <= N;
         j++) {
      lp[i * pr[j]] = pr[j];
    }
  }

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> vvod;

    mas.push_back(vvod);
  }

  for (auto i : mas) {
    lispr = {};
    fact(i);
    if (lispr.size()) {
      prcnt[lispr[0]]++;
      for (int j = 0; j < int(lispr.size()) - 1; j++) {
        if (lispr[j + 1] != lispr[j]) {
          prcnt[lispr[j + 1]]++;
        }
      }
    }
  }

  for (auto i : prcnt) {
    if (i.s > 1) {
      pair_copr = 1;
    }

    if (i.s == n) {
      set_copr = 1;
    }
  }

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

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

const int N = 1e6 + 5;

unordered_map<int, int> prcnt;
int lp[N], n, vvod, pair_copr, set_copr;
vector<int> pr, lispr, mas;

void fact(int chis) {
  if (chis <= 1) {
    return;
  }

  lispr.push_back(lp[chis]);

  fact(chis / lp[chis]);
}

int main() {
  ios_base::sync_with_stdio(0);
  // freopen( "input.txt", "r", stdin );

  for (int i = 2; i <= N; i++) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }

    for (int j = 0; j < int(pr.size()) && pr[j] <= lp[i] && i * pr[j] <= N;
         j++) {
      lp[i * pr[j]] = pr[j];
    }
  }

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> vvod;

    mas.push_back(vvod);
  }

  for (auto i : mas) {
    lispr = {};
    fact(i);
    prcnt[lispr[0]]++;
    for (int j = 0; j < int(lispr.size()) - 1; j++) {
      if (lispr[j + 1] != lispr[j]) {
        prcnt[lispr[j + 1]]++;
      }
    }
  }

  for (auto i : prcnt) {
    if (i.s > 1) {
      pair_copr = 1;
    }

    if (i.s == n) {
      set_copr = 1;
    }
  }

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

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

ll gcd(ll a, ll b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}

ll gcd_arr(vector<ll> a) {
  int n = a.size();
  for (int i = n - 2; i >= 0; i--) {
    a[i] = gcd(a[i], a[i + 1]);
  }
  return a.front();
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> data;

  REP(i, n) {
    ll x;
    cin >> x;
    data.push_back(x);
  }

  map<ll, int> prime_memo;

  bool gcd_all_1 = true;
  REP(i, n) {
    map<ll, int> tmp = prime_factor(data[i]);
    for (auto p : tmp) {
      if (prime_memo[p.first] != 0) {
        gcd_all_1 = false;
        break;
      } else {
        prime_memo[p.first] = 1;
      }
    }
  }

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

  ll gcd_all_2 = gcd_arr(data);
  if (gcd_all_2 == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

ll gcd(ll a, ll b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}

ll gcd_arr(vector<ll> a) {
  int n = a.size();
  for (int i = n - 2; i >= 0; i--) {
    a[i] = gcd(a[i], a[i + 1]);
  }
  return a.front();
}

int main() {
  int n;
  cin >> n;
  vector<ll> data;
  REP(i, n) {
    ll x;
    cin >> x;
    data.push_back(x);
  }
  bool gcd_all_1 = true;
  REP(i, n - 1) {
    FOR(j, i + 1, n) {
      if (gcd(data[i], data[j]) != 1)
        gcd_all_1 = false;
    }
  }
  if (gcd_all_1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

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

#include <bits/stdc++.h>
using namespace std;
int n, s[1000003], t[1000003], tmp, x;
long long prime[1100000], tot, d[1100003];
void find() {
  for (long long i = 2; i <= 1100000; i++) {
    if (d[i] == 0) {
      prime[++tot] = i;
      d[i] = i;
    }
    for (long long j = 1; j <= tot && prime[j] <= d[i]; j++) {
      if (prime[j] * i <= 1100000)
        d[prime[j] * i] = prime[j];
      else
        break;
    }
  }
}
int main() {
  find();
  scanf("%d", &n);
  scanf("%d", &tmp);
  s[tmp]++;
  x = tmp;
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &tmp);
    x = __gcd(tmp, x);
    s[tmp]++;
  }
  if (x != 1) {
    printf("not coprime\\n");
    return 0;
  }
  for (int i = 2; i <= 1000000; ++i) {
    if (s[i] == 0)
      continue;
    if (s[i] > 1) {
      printf("setwise coprime\\n");
      return 0;
    }
    int lst = 0, tmp = i;
    while (d[tmp] != 0) {
      if (d[tmp] == lst) {
        tmp /= d[tmp];
        continue;
      }
      t[d[tmp]]++;
      lst = d[tmp];
      if (t[d[tmp]] > 1) {
        printf("setwise coprime\\n");
        return 0;
      }
      tmp /= d[tmp];
    }
  }
  printf("pairwise coprime\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, s[1000003], t[1000003], tmp, x;
long long prime[1100000], tot, d[1100003];
void find() {
  for (long long i = 2; i <= 1100000; i++) {
    if (d[i] == 0) {
      prime[++tot] = i;
      d[i] = i;
    }
    for (long long j = 1; j <= tot && prime[j] <= d[i]; j++) {
      if (prime[j] * i <= 1100000)
        d[prime[j] * i] = prime[j];
      else
        break;
    }
  }
}
int main() {
  find();
  scanf("%d", &n);
  scanf("%d", &tmp);
  s[tmp]++;
  x = tmp;
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &tmp);
    x = __gcd(tmp, x);
    s[tmp]++;
  }
  if (x != 1) {
    printf("not coprime\\n");
    return 0;
  }
  for (int i = 2; i <= 1000000; ++i) {
    if (s[i] == 0)
      continue;
    if (s[i] > 1) {
      printf("setwise coprime\\n");
      return 0;
    }
    for (int j = 1; prime[j] <= i; ++j) {
      if (i % prime[j] == 0) {
        t[prime[j]]++;
        if (t[prime[j]] > 1) {
          printf("setwise coprime\\n");
          return 0;
        }
      }
    }
  }
  printf("pairwise coprime\\n");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> val(1000001, 0);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) {
    int vali = a[i];
    for (int j = 2; j * j <= vali; j++) {
      if (vali % j == 0) {
        val[j]++;
        vali /= j;
      }
      while (vali % j == 0) {
        vali /= j;
      }
    }
    if (vali != 1)
      val[vali]++;
  }
  //  cout << val[2] << endl;
  bool pair = true;
  rep(i, 2, 1000001) {
    if (val[i] == n) {
      cout << "not coprime" << endl;
      return 0;
    }
    if (val[i] >= 2)
      pair = false;
  }
  if (pair) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  cout << "setwise coprime" << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<ll> check(1000000);
  rep(i, 0, n) cin >> a[i];
  bool pairwise = true;
  rep(i, 2, n) {
    ll cnt = 0;
    rep(j, 0, n) {
      if (a[j] % i == 0)
        cnt++;
      if (cnt >= 2)
        pairwise = false;
    }
    if (cnt == n) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  if (pairwise)
    cout << "pairwise coprime" << endl;
  else
    cout << "setwise coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 * author: Behradm
 * Created: 2020.08.29 17:56:18
 * In The Name of God
 **/
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;
int a[N], cnt[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      gcd = a[0];
    else
      gcd = __gcd(gcd, a[i]);
  }

  bool bad = false;
  for (int i = 0; i < n; i++) {
    bool prime = true;
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        prime = false;
        cnt[j]++;
        if (a[i] / j != j)
          cnt[a[i] / j]++;
        if (cnt[j] > 1 || cnt[a[i] / j] > 1) {
          bad = true;
          break;
        }
      }
    }
    if (prime && a[i] != 1) {
      cnt[a[i]]++;
      if (cnt[a[i]] > 1) {
        bad = true;
      }
    }
    if (bad)
      break;
  }

  if (!bad) {
    cout << "pairwise coprime\\n";
  } else if (gcd == 1) {
    cout << "setwise coprime\\n";
  } else {
    cout << "not coprime\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

/**
 * author: Behradm
 * Created: 2020.08.29 17:56:18
 * In The Name of God
 **/
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;
int a[N], cnt[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      gcd = a[0];
    else
      gcd = __gcd(gcd, a[i]);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        cnt[j]++;
        if (a[i] / j != j)
          cnt[a[i] / j]++;
      }
    }
  }

  int mx = 1;
  for (int i = *max_element(a, a + n); i >= 0; i--) {
    if (cnt[i] > 1) {
      mx = i;
      break;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int, int>;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  Sieve sieve(1e6);
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll memo = 0;
  for (ll i = 0; i < n; i++) {
    memo = __gcd(memo, a[i]);
  }
  map<ll, ll> mp;
  for (ll i = 0; i < n; i++) {
    const auto &res = sieve.factor(a[i]);
    for (auto p : res)
      mp[p.first]++;
  }
  bool flag = true;
  for (auto p : mp) {
    if (p.second > 1)
      flag = false;
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
  } else if (!flag && memo == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

ll gcd(ll x, ll y) {
  ll r;
  if (x < y) {
    swap(x, y);
  }
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

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

int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll memo = a[0];
  for (ll i = 1; i < n; i++) {
    memo = gcd(memo, a[i]);
  }
  map<ll, ll> mp;
  for (ll i = 0; i < n; i++) {
    const auto &res = prime_factorize(a[i]);
    for (auto p : res)
      mp[p.first]++;
  }
  bool flag = true;
  for (auto p : mp) {
    if (p.second > 1)
      flag = false;
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
  } else if (!flag && memo == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}