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

#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define debug(var) cout << #var << ": " << var << endl;
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int N = 1e6 + 5;

array<int, N> gpd;
void Eratosthenes_sieve(int n) {
  for (int i = 2; i < n; i++)
    if (!gpd[i])
      for (int j = i; j < n; j += i)
        gpd[j] = i;
}

int flag_pairwise;
unordered_set<int> used_prime;
void prime_factorize(ll x) {
  while (x > 1) {
    int p = gpd[x];
    int cnt = 0;
    while (x % p == 0)
      x /= p, cnt++;
    // store or process with p, cnt...
    if (used_prime.find(p) != used_prime.end())
      flag_pairwise = 0;
    used_prime.insert(p);
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  Eratosthenes_sieve(N);

  int n;
  cin >> n;

  int gcd_sum;
  flag_pairwise = 1;
  set<int> used_prime;
  for (int i = 0; i < n; i++) {
    int e;
    cin >> e;
    prime_factorize(e);
    gcd_sum = i == 0 ? e : __gcd(gcd_sum, e);
  }
  cout << (flag_pairwise  ? "pairwise coprime"
           : gcd_sum == 1 ? "setwise coprime"
                          : "not coprime");
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define debug(var) cout << #var << ": " << var << endl;
using namespace std;
using ll = long long;
using pii = pair<int, int>;

// primes in [1, n]
vector<int> primes, phi, vis;
void euler_sieve(int n) {
  primes.reserve((n + 1) >> 1); // -> n / log(n);
  phi = vector<int>(n + 1);
  vis = vector<int>(n + 1);
  phi[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!vis[i]) {
      phi[i] = i - 1;
      primes.emplace_back(i);
    }
    for (int p : primes) {
      if ((ll)i * p >= n + 1)
        break;
      vis[i * p] = 1;
      if (i % p)
        phi[i * p] = phi[i] * (p - 1);
      else {
        phi[i * p] = phi[i] * p;
        break;
      }
    }
  }
}

int flag_pairwise;
unordered_set<int> used_prime;

// calculate prime divisors in x
void prime_factorize(ll x) {
  // ll _x = x;

  // enumerate primes less than sqrt(x)
  // for (ll p = 2; p * p <= x; i++) if(x % p == 0) {
  // for (int i = 0, p; i < (int)primes.size(); i++) {
  //     p = primes[i];
  for (ll p : primes) {
    if (x % p)
      continue;
    int cnt = 0;
    while (x % p == 0)
      x /= p, cnt++;
    // store or process with p, cnt, p ^ cnt...
    if (used_prime.find(p) != used_prime.end())
      flag_pairwise = 0;
    used_prime.insert(p);
  }
  if (x != 1) { // last prime divisor
    int p = x, cnt = 1;
    // store or process with p, cnt, p ^ cnt...
    if (used_prime.find(p) != used_prime.end())
      flag_pairwise = 0;
    used_prime.insert(p);
  }
}

const int N = 1e6 + 5;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  euler_sieve(N);

  int n;
  cin >> n;

  int gcd_sum;
  flag_pairwise = 1;
  set<int> used_prime;
  for (int i = 0; i < n; i++) {
    int e;
    cin >> e;
    prime_factorize(e);
    gcd_sum = i == 0 ? e : __gcd(gcd_sum, e);
  }
  cout << (flag_pairwise  ? "pairwise coprime"
           : gcd_sum == 1 ? "setwise coprime"
                          : "not coprime");
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 100;
int n, x, ans, maxx, res, i, j, num[N];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> n >> ans;
  num[ans]++;
  for (i = 2; i <= n; i++) {
    cin >> x;
    num[x]++;
    maxx = max(maxx, x);
    ans = gcd(ans, x);
  }
  if (ans != 1)
    cout << "not coprime\\n";
  else {
    for (i = 2; i <= maxx; i++) {
      for (j = i, res = 0; j <= maxx; j += i)
        res += num[j];
      if (res > 1) {
        cout << "setwise coprime";
        return 0;
      }
    }
    cout << "pairwise coprime\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
int n, flag, ans, i, j, k, a[N], vis[N];
int gcd(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  ans = a[1];
  for (i = 2; i <= n; i++)
    ans = gcd(ans, a[i]);
  if (ans != 1)
    cout << "not coprime\\n";
  else {
    for (i = 1; i < n; i++)
      for (j = i + 1; j <= n; j++)
        if (gcd(a[i], a[j]) != 1) {
          cout << "setwise coprime\\n";
          return 0;
        }
    cout << "pairwise coprime\\n";
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, N) for (ll i = 0; i < N; i++)
using ll = long long;
using namespace std;
#define MOD 1000000007
typedef pair<ll, ll> Pl;
typedef vector<int> vi;

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

  // エラトステネスの篩
  int P_MAX = 1000005;
  vector<int> pmn(P_MAX, -1); // smallest prime number that can divide i(pmn[i]
                              // == i -> i is prime number)
  // vector<int> plst;               //prime number list
  // plst.emplace_back(2);
  for (int i = 1; i < P_MAX; i++)
    if (i % 2 == 0)
      pmn[i] = 2;
    else
      pmn[i] = i;
  for (int i = 3; i * i < P_MAX; i += 2) {
    if (pmn[i] == i) {
      // plst.emplace_back(i);
      for (int j = 3 * i; j < P_MAX; j += 2 * i)
        if (pmn[j] == j)
          pmn[j] = i;
    }
  }

  int flag = 2;
  vector<int> cnt(P_MAX, 0);
  rep(i, n) {
    while (a[i] != 1) {
      int apmn = pmn[a[i]];
      cnt[apmn]++;
      while (a[i] % apmn == 0)
        a[i] /= apmn;
    }
  }
  rep(i, cnt.size()) {
    if (cnt[i] > 1) {
      if (cnt[i] == n) {
        flag = 0;
        break;
      }
      flag = 1;
    }
  }

  if (flag == 2) {
    puts("pairwise coprime");
  } else if (flag == 1) {
    puts("setwise coprime");
  } else {
    puts("not coprime");
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, N) for (ll i = 0; i < N; i++)
using ll = long long;
using namespace std;
#define MOD 1000000007
typedef pair<ll, ll> Pl;
typedef vector<int> vi;

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

  // エラトステネスの篩
  int P_MAX = 1000005;
  vector<int> pmn(P_MAX, -1); // smallest prime number that can divide i(pmn[i]
                              // == i -> i is prime number)
  // vector<int> plst;               //prime number list
  // plst.emplace_back(2);
  for (int i = 2; i < P_MAX; i += 2)
    pmn[i] = 2;
  for (int i = 3; i * i < P_MAX; i += 2) {
    if (pmn[i] == -1) {
      // plst.emplace_back(i);
      for (int j = i; j < P_MAX; j += 2 * i)
        if (pmn[j] == -1)
          pmn[j] = i;
    }
  }

  int flag = 2;
  vector<int> cnt(P_MAX, 0);
  rep(i, n) {
    cnt[pmn[a[i]]]++;
    if (flag == 2 && cnt[pmn[a[i]]] > 1)
      flag = 1;
  }
  if (flag == 1 && cnt[pmn[a[0]]] == n)
    flag = 0;

  if (flag == 2) {
    puts("pairwise coprime");
  } else if (flag == 1) {
    puts("setwise coprime");
  } else {
    puts("not coprime");
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define sf scanf
#define pf printf
#define pi acos(-1)
#define time_save                                                              \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
ll ar[1000006];

#define mx 1000005
ll prime[mx];

bool vis[mx];

void sieve() {
  ll x = sqrt((ll)mx);
  for (ll i = 3; i <= x; i += 2) {
    if (vis[i] == 0) {
      for (ll j = i * i; j < mx; j += 2 * i)
        vis[j] = 1;
    }
  }
  prime[0] = 2;
  ll in = 1;
  for (ll i = 3; i < mx; i += 2) {
    if (vis[i] == 0) {
      prime[in] = i;
      in++;
    }
  }
}
int main() {
  sieve();
  // time_save;
  ll n, gc;
  map<ll, ll> mp;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> ar[i];
  }
  gc = ar[0];
  for (ll i = 1; i < n; i++) {
    gc = __gcd(gc, ar[i]);
  }
  ll flag = 0;
  if (gc == 1) {
    for (ll i = 0; i < n; i++) {
      ll val = ar[i];
      for (ll j = 0; prime[j] <= sqrt(ar[i]); j++) {
        if (val % prime[j] == 0) {
          mp[prime[j]]++;
          if (mp[prime[j]] > 1) {
            flag = 1;
            break;
          }
          while (val % prime[j] == 0)
            val /= prime[j];
        }
      }
      if (val != 1)
        mp[val]++;
      if (mp[val] > 1) {
        flag = 1;
        break;
      }
    }
    if (flag == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "pairwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define sf scanf
#define pf printf
#define pi acos(-1)
#define time_save                                                              \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
ll ar[1000006];

#define mx 1000005
ll prime[mx];

bool vis[mx];

void sieve() {
  ll x = sqrt((ll)mx);
  for (ll i = 3; i <= x; i += 2) {
    if (vis[i] == 0) {
      for (ll j = i * i; j < mx; j += 2 * i)
        vis[j] = 1;
    }
  }
  prime[0] = 2;
  ll in = 1;
  for (ll i = 3; i < mx; i += 2) {
    if (vis[i] == 0) {
      prime[in] = i;
      in++;
    }
  }
}
int main() {
  sieve();
  // time_save;
  ll n, gc;
  map<ll, ll> mp;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> ar[i];
  }
  gc = ar[0];
  for (ll i = 1; i < n; i++) {
    gc = __gcd(gc, ar[i]);
  }
  ll flag = 0;
  if (gc == 1) {
    for (ll i = 0; i < n; i++) {
      ll val = ar[i];
      for (ll j = 0; prime[j] <= ar[i]; j++) {
        if (val % prime[j] == 0) {
          mp[prime[j]]++;
          if (mp[prime[j]] > 1) {
            flag = 1;
            break;
          }
          while (val % prime[j] == 0)
            val /= prime[j];
        }
      }
    }
    if (flag == 1)
      cout << "setwise coprime" << endl;
    else
      cout << "pairwise coprime" << endl;
  } else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
const int maxn = 1e6 + 5;
int N, A[maxn], f[maxn];
vector<int> primes;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void seive() {
  vector<bool> vis(maxn, false);
  for (int i = 2; i < maxn; ++i) {
    if (vis[i]) {
      continue;
    }
    for (int j = i; j < maxn / i; ++j) {
      vis[i * j] = true, f[i * j] = i;
    }
  }
  for (int i = 2; i < maxn; ++i)
    if (!vis[i])
      primes.push_back(i);
}
int main() {
  //    freopen("in.txt", "r", stdin);
  //    freopen("out.txt", "w", stdout);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  // Check pairwise coprime.
  seive();
  bool pairPirme = true;
  unordered_set<int> visFac;
  for (int i = 0; i < N; ++i) {
    int t = A[i];
    while (f[t]) {
      int p = f[t];
      while (t % p == 0)
        t /= p;
      if (visFac.count(p))
        pairPirme = false;
      visFac.insert(p);
    }
    if (t > 1) {
      if (visFac.count(t))
        pairPirme = false;
      visFac.insert(t);
    }
  }

  // Check setwise coprime.
  int t = A[0];
  for (int i = 1; i < N; ++i) {
    t = gcd(t, A[i]);
  }
  bool setPrime = (t == 1);

  if (pairPirme)
    cout << "pairwise coprime" << endl;
  else if (setPrime)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
const int maxn = 1e6 + 5;
int N, A[maxn], f[maxn];
vector<int> primes;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void seive() {
  vector<bool> vis(maxn, false);
  for (int i = 2; i < maxn; ++i) {
    if (vis[i]) {
      f[i] = i;
      continue;
    }
    for (int j = i; i * j < maxn; ++j) {
      vis[i * j] = true, f[i * j] = i;
      //            printf("f[%d] = %d\\n", i * j, i);
    }
  }
  for (int i = 2; i < maxn; ++i)
    if (!vis[i])
      primes.push_back(i);
}
int main() {
  //    freopen("in.txt", "r", stdin);
  //    freopen("out.txt", "w", stdout);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  // Check pairwise coprime.
  seive();
  bool pairPirme = true;
  unordered_set<int> visFac;
  for (int i = 0; i < N; ++i) {
    int t = A[i];
    while (f[t] != t) {
      int p = f[t];
      while (t % p == 0)
        t /= p;
      if (visFac.count(p))
        pairPirme = false;
      visFac.insert(p);
    }
    if (f[t] == t) {
      if (visFac.count(t))
        pairPirme = false;
      visFac.insert(t);
    }
  }

  // Check setwise coprime.
  int t = A[0];
  for (int i = 1; i < N; ++i) {
    t = gcd(t, A[i]);
  }
  bool setPrime = (t == 1);

  if (pairPirme)
    cout << "pairwise coprime" << endl;
  else if (setPrime)
    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 int
ll gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll cnt[1000009];
int main() {
  long long int a[100000], p = 0, i, j;

  int n;
  ll ans = 0;
  cin >> n;
  long long int b[n + 9];
  for (i = 0; i < n; i++) {
    cin >> p;
    cnt[p]++;
    ans = gcd(ans, p);
  }
  if (ans > 1)
    cout << "not coprime" << endl;

  else {
    ll x = 0;
    for (i = 2; i <= 1000000; i++) {
      x = 0;
      for (j = i; j <= 1000000; j += i) {
        x += cnt[j];
      }
      if (x > 1)
        break;
    }

    if (x > 1)
      cout << "setwise coprime" << endl;
    else
      cout << "pairwise coprime" << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool status[1100002];
void siv() {
  int N = 1000000;
  int sq = sqrt(N);
  for (int i = 4; i <= N; i += 2)
    status[i] = 1;
  for (int i = 3; i <= sq; i += 2) {
    if (status[i] == 0) {
      for (int j = i * i; j <= N; j += i)
        status[j] = 1;
    }
  }
}
int main() {
  siv();
  long long int a[100000], p = 0;
  for (int i = 2; i < 10000; i++) {
    if (!status[i]) {
      a[p++] = i;
    }
  }
  // cout<<p<<endl;
  int n;
  cin >> n;
  long long int b[n + 9];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  ll ans = b[0];
  for (int i = 1; i < n; i++) {
    ans = gcd(ans, b[i]);
  }
  if (ans != 1)
    cout << "not coprime" << endl;
  else {
    ll i, j;
    ans = 0;
    ll s = 0, ok = 0;
    for (i = 0; i < p; i++) {
      s = 0, ok = 0;
      for (j = 0; j < n; j++) {
        ok = gcd(a[i], b[j]);
        if (ok != 1)
          s++;
      }
      ans = max(s, ans);
    }
    if (ans == 1)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int main() {
  int N;
  std::cin >> N;
  std::map<int, int> map;

  for (int i = 0; i < N; i++) {
    int val;
    std::cin >> val;
    for (int j = 2; j < std::sqrt(val) + 1; j++) {
      if (val % j == 0) {
        if (map.find(j) == map.end()) {
          map[j] = 1;
        } else {
          map[j]++;
        }
      }
      while (val % j == 0) {
        val /= j;
      }
    }
    if (val > 1) {
      if (map.find(val) == map.end()) {
        map[val] = 1;
      } else {
        map[val]++;
      }
    }
  }

  bool is_pc = true;
  bool is_sc = true;
  for (auto pair : map) {
    if (pair.second > 1) {
      is_pc = false;
    }
    if (pair.second == N) {
      is_sc = false;
    }
  }
  if (is_pc) {
    std::cout << "pairwise coprime" << std::endl;
  } else if (is_sc) {
    std::cout << "setwise coprime" << std::endl;
  } else {
    std::cout << "not coprime" << std::endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  int N;
  std::cin >> N;
  std::map<int, int> map;

  for (int i = 0; i < N; i++) {
    int val;
    std::cin >> val;
    for (int j = 2; j < 1000; j++) {
      if (val % j == 0) {
        if (map.find(j) == map.end()) {
          map[j] = 1;
        } else {
          map[j]++;
        }
      }
      while (val % j == 0) {
        val /= j;
      }
    }
    if (val > 1000) {
      if (map.find(val) == map.end()) {
        map[val] = 1;
      } else {
        map[val]++;
      }
    }
  }

  bool is_pc = true;
  bool is_sc = true;
  for (auto pair : map) {
    if (pair.second > 1) {
      is_pc = false;
    }
    if (pair.second == N) {
      is_sc = false;
    }
  }
  if (is_pc) {
    std::cout << "pairwise coprime" << std::endl;
  } else if (is_sc) {
    std::cout << "setwise coprime" << std::endl;
  } else {
    std::cout << "not coprime" << std::endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define HAS_TEST_CASE 0

namespace rG {

typedef long long ll;

const int N = 1e6;

int n, m, k, a[N + 10];
char s[N + 10];
int prime[N + 10], totp, notPrime[N + 10];
std::set<int> cnt[N + 10];
int cntt[N + 10];

void init() {
  notPrime[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (!notPrime[i])
      prime[++totp] = i;
    for (int j = 1; j <= totp && i * prime[j] <= N; j++) {
      notPrime[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}

#define pc puts("pairwise coprime")
#define sc puts("setwise coprime")
#define no puts("not coprime")

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

inline void main() {
  init();
  scanf("%d", &n);
  bool f1 = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    for (int j = 1; j <= sqrt(a[i]); j++) {
      if (a[i] % j == 0 && !notPrime[j])
        cntt[j]++;
      if (a[i] % j == 0 && j * j != a[i] && !notPrime[a[i] / j])
        cntt[a[i] / j]++;
      if (cntt[j] >= 2) {
        f1 = 0;
        break;
      }
      if (a[i] % j == 0 && cntt[a[i] / j] >= 2) {
        f1 = 0;
        break;
      }
    }
    if (f1 == 0) {
      for (int j = i + 1; j <= n; j++)
        scanf("%d", a + j);
      break;
    }
  }
  if (f1 == 1)
    return pc, void();
  int gcdd = a[1];
  for (int i = 2; i <= n; i++)
    gcdd = gcd(gcdd, a[i]);
  if (gcdd == 1)
    return sc, void();
  else
    no;
}

} // namespace rG

int main() {
#if defined(LOCAL) && HAS_TEST_CASE
  freopen("tmp.out", "w", stdout);
#endif
#if HAS_TEST_CASE
  int T;
  scanf("%d", &T);
  while (T--)
    rG::main();
#else
  rG::main();
#endif
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define HAS_TEST_CASE 0

namespace rG {

typedef long long ll;

const int N = 1e6;

int n, m, k, a[N + 10];
char s[N + 10];
int prime[N + 10], totp, notPrime[N + 10];
std::set<int> cnt[N + 10];
int cntt[N + 10];

void init() {
  notPrime[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (!notPrime[i])
      prime[++totp] = i;
    for (int j = 1; j <= totp && i * prime[j] <= N; j++) {
      notPrime[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}

#define pc puts("pairwise coprime")
#define sc puts("setwise coprime")
#define no puts("not coprime")

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

inline void main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    for (int j = 1; j <= totp && prime[j] <= a[i]; j++)
      if (a[i] % prime[j] == 0) {
        cntt[prime[j]]++;
      }
  }
  bool f1 = 1;
  for (int i = 1; i <= totp; i++)
    if (cntt[prime[i]] >= 2) {
      f1 = 0;
      break;
    }
  if (f1 == 1)
    return pc, void();
  int gcdd = a[1];
  for (int i = 2; i <= n; i++)
    gcdd = gcd(gcdd, a[i]);
  if (gcdd == 1)
    return sc, void();
  else
    no;
}

} // namespace rG

int main() {
#if defined(LOCAL) && HAS_TEST_CASE
  freopen("tmp.out", "w", stdout);
#endif
#if HAS_TEST_CASE
  int T;
  scanf("%d", &T);
  while (T--)
    rG::main();
#else
  rG::main();
#endif
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstdlib>

using namespace std;

const int N = 1000010;
int n, a[N], p[N];
bool pd;

inline void re(int &x) {
  x = 0;
  bool flag = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9')
    flag |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = flag ? -x : x;
}

void divd(int x) {
  int i;
  for (i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      p[i]++;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    p[x]++;
}

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

int main() {
  int i;
  re(n);
  for (i = 1; i <= n; i++) {
    re(a[i]);
    divd(a[i]);
  }
  for (i = 1; i <= N - 10; i++)
    if (p[i] > 1)
      pd = 1;
  if (!pd) {
    printf("pairwise coprime");
  } else {
    int g = a[1];
    for (i = 2; i <= n; i++)
      g = gcd(g, a[i]);
    if (g == 1)
      printf("setwise coprime");
    else
      printf("not coprime");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>

using namespace std;

const int N = 1000010;
int n, a[N], p[N];
bool pd;

inline void re(int &x) {
  x = 0;
  bool flag = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9')
    flag |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = flag ? -x : x;
}

void divd(int x) {
  int i, sqrtx = (int)sqrt(x);
  for (i = 2; i <= sqrtx; i++) {
    if (x % i == 0) {
      p[i]++;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    p[x]++;
}

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

int main() {
  int i;
  re(n);
  for (i = 1; i <= n; i++) {
    re(a[i]);
    divd(a[i]);
  }
  for (i = 1; i <= N - 10; i++)
    if (p[i] > 1)
      pd = 1;
  if (!pd) {
    printf("pairwise coprime");
  } else {
    int g = a[1];
    for (i = 2; i <= n; i++)
      g = gcd(g, a[i]);
    if (g == 1)
      printf("setwise coprime");
    else
      printf("not coprime");
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long

template <typename T> void drop(const T &x) {
  cout << x << '\\n';
  exit(0);
}

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

void solve() {
  int N = 1e6 + 5;
  int n;
  cin >> n;
  vector<int> count(N);
  int all = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    count.at(a)++;
    all = gcd(all, a);
  }
  bool ok = true;
  for (int i = 2; i < N && ok; ++i) {
    int sum = 0;
    for (int j = i; j < N; j += i)
      sum += count[j];
    if (sum > 1)
      ok = false;
  }
  cout << (ok         ? "pairwise coprime"
           : all == 1 ? "setwise coprime"
                      : "not coprime")
       << '\\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    solve();

  return 0;
}


Error: 0

Fixed submission:

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

#define ll long long

template <typename T> void drop(const T &x) {
  cout << x << '\\n';
  exit(0);
}

void solve() {
  int n;
  cin >> n;
  vector<int> count(1e6);
  int all = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    count.at(a)++;
    all = __gcd(all, a);
  }
  bool ok = true;
  for (int i = 2; i < n && ok; ++i) {
    int sum = 0;
    for (int j = i; j < n; j += i)
      sum += count[j];
    if (sum > 1)
      ok = false;
  }
  cout << (ok         ? "pairwise coprime"
           : all == 1 ? "setwise coprime"
                      : "not coprime")
       << '\\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    solve();

  return 0;
}