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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, j, n) for (int i = j; i < (int)(n); i++)
#define brep(i, n) for (int i = n; i > 0; i--)
#define BREP(i, j, n) for (int i = n; i > j; i--)
#define TEST cout << "PASS" << endl
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main() {
  int n;
  cin >> n;
  int table[2'000'000];
  int lis[2'000'000];
  fill(lis, lis + 2'000'000, 0);
  fill(table, table + 2'000'000, 0);
  for (int i = 2; i < 2'000'000; i++) {
    if (lis[i] == 0) {
      lis[i] = 1;
      for (int j = 2; i * j < 2'000'000; j++) {
        if (lis[i * j] == 0)
          lis[i * j] = i;
      }
    }
  }
  lis[2] = 1;
  lis[1] = 1;
  lis[0] = 1;
  bool flag = true;
  rep(i, n) {
    int a;
    cin >> a;
    int j = a;
    while (1) {
      int k = lis[j];
      if (table[k] && k != 1)
        flag = false;
      table[k]++;
      if (lis[j] == 1) {
        if (table[j] && j != 1)
          flag = false;
        table[j]++;
      }
      if (k == 1)
        break;
      while (lis[j] == k || j == k)
        j /= k;
      if (j == 1)
        break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  for (int i = 2; i < 2'000'000; i++) {
    if (table[i] == n) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, j, n) for (int i = j; i < (int)(n); i++)
#define brep(i, n) for (int i = n; i > 0; i--)
#define BREP(i, j, n) for (int i = n; i > j; i--)
#define TEST cout << "PASS" << endl
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main() {
  int n;
  cin >> n;
  int table[2000000];
  int lis[2000000];
  fill(lis, lis + 2000000, 0);
  fill(table, table + 2000000, 0);
  for (int i = 2; i < 2000000; i++) {
    if (lis[i] == 0) {
      lis[i] = 1;
      for (int j = 2; i * j < 2000000; j++) {
        if (lis[i * j] == 0)
          lis[i * j] = i;
      }
    }
  }
  lis[2] = 1;
  bool flag = true;
  rep(i, n) {
    int a;
    cin >> a;
    int j = a;
    while (1) {
      int k = lis[j];
      if (table[k] && k != 1)
        flag = false;
      table[k]++;
      if (lis[j] == 1) {
        if (table[j] && j != 1)
          flag = false;
        table[j]++;
      }
      if (k == 1)
        break;
      while (lis[j] == k || j == k)
        j /= k;
      if (j == 1)
        break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  for (int i = 2; i < 2000000; i++) {
    if (table[i] == n) {
      cout << "not coprime" << endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
ll M = 1e9 + 7;

#define MAXN 10000005
ll spf[MAXN];
ll hash1[MAXN] = {0};
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;
  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;
  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

void getFactorization(ll x) {
  ll temp;
  while (x != 1) {
    temp = spf[x];

    if (x % temp == 0) {
      hash1[spf[x]]++;

      x = x / spf[x];
    }
    while (x % temp == 0)
      x = x / temp;
  }
}

bool check(ll x) {
  ll temp;
  while (x != 1) {
    temp = spf[x];
    if (x % temp == 0 && hash1[temp] > 1)
      return false;
    while (x % temp == 0)
      x = x / temp;
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  sieve();
  vector<ll> vec(n + 1, 0);
  bool bb = 1;
  for (ll i = 1; i <= n; i++) {
    cin >> vec[i];
    getFactorization(vec[i]);
  }

  for (ll i = 1; i <= n; i++) {
    if (check(vec[i]) == 0) {
      bb = 0;
      break;
    }
  }

  if (bb == 1) {
    cout << "pairwise coprime" << endl;
  } else {
    ll g = vec[1];
    for (ll i = 2; i <= n; i++) {
      g = __gcd(g, vec[i]);
    }
    if (g == 1) {
      cout << "setwise coprime" << endl;
    } else {
      cout << "not coprime" << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
ll M = 1e9 + 7;

#define MAXN 1005
ll spf[MAXN];
ll hash1[MAXN] = {0};
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;
  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;
  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

void getFactorization(ll x, ll i, bool &bb) {
  ll temp;
  while (x != 1) {
    temp = spf[x];

    if (x % temp == 0) {
      //			if(hash1[spf[x]]<i){
      //				bb=0;
      //				break;
      //			}
      hash1[spf[x]]++;

      x = x / spf[x];
    }
    while (x % temp == 0)
      x = x / temp;
  }
}

bool check(ll x) {
  ll temp;
  while (x != 1) {
    temp = spf[x];

    // Checking whether it common
    // prime factor with other numbers
    if (x % temp == 0 && hash1[temp] > 1)
      return false;
    while (x % temp == 0)
      x = x / temp;
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  sieve();
  vector<ll> vec(n + 1, 0);
  bool bb = 1;
  for (ll i = 1; i <= n; i++) {
    cin >> vec[i];
    getFactorization(vec[i], i, bb);
    if (bb == 0)
      break;
  }

  for (ll i = 1; i <= n; i++) {
    if (check(i) == 0) {
      bb = 0;
      break;
    }
  }

  if (bb == 1) {
    cout << "pairwise coprime" << endl;
  } else {
    ll g = vec[1];
    for (ll i = 2; i <= n; i++) {
      g = __gcd(g, vec[i]);
    }
    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 < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

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

int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i, N) cin >> A[i];

  map<int, int> G;

  // 1
  bool ok = true;
  rep(i, N) {
    int x = A[i];
    //  cout << "A[i]: " << A[i] << endl;
    for (int j = 2; j <= sqrt(A[i]); j++) {
      if (G[j] != 0 && G[j] != 1) {
        ok = false;
        break;
      }
      if (x == 1)
        break;
      if (x % j != 0)
        continue;
      while (x % j == 0) {
        x /= j;
      }
      //  cout << "  x:" << x << endl;
      G[j]++;
    }
    if (!ok)
      break;
    if (x != 1)
      G[x]++;
  }

  for (auto x : G) {
    // cout << x.first << " " << x.second << endl;
    if (x.second != 0 && x.second != 1) {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  // 2
  ok = true;
  int y = A[0];
  rep(i, N - 1) {
    y = gcd(y, A[i + 1]);
    if (y == 1)
      break;
  }
  if (y != 1)
    ok = false;
  if (ok) {
    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 < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

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

int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i, N) cin >> A[i];

  map<int, int> G;

  // 1
  bool ok = true;
  rep(i, N) {
    int x = A[i];
    //  cout << "A[i]: " << A[i] << endl;
    for (int j = 2; j <= sqrt(A[i]); j++) {
      if (G[j] != 0 && G[j] != 1) {
        ok = false;
        break;
      }
      if (x == 1)
        break;
      if (x % j != 0)
        continue;
      while (x % j == 0) {
        x /= j;
      }
      //  cout << "  x:" << x << endl;
      G[j]++;
    }
    if (x != 1)
      G[x]++;
  }

  for (auto x : G) {
    // cout << x.first << " " << x.second << endl;
    if (x.second != 1) {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  // 2
  ok = true;
  int y = A[0];
  rep(i, N - 1) {
    y = gcd(y, A[i + 1]);
    if (y == 1)
      break;
  }
  if (y != 1)
    ok = false;
  if (ok) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);

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

  long long g = a[0];
  for (long long i = 0; i < n; i++) {
    g = gcd(a[i], g);
  }

  if (g > 1) {
    printf("not coprime\\n");
    return 0;
  }

  vector<bool> is_prime(1100000, true);
  is_prime[0] = false;
  is_prime[1] = false;

  for (long long i = 2; i < 1100000; i++) {
    if (is_prime[i] == false)
      continue;
    for (long long j = i * 2; j < 1100000; j += i) {
      is_prime[j] = false;
    }
  }

  vector<long long> primes;
  vector<long long> not_primes;
  vector<bool> used(1100000, false);
  vector<long long> small_prime;

  for (long long i = 0; i < 1100; i++) {
    if (is_prime[i] == true)
      small_prime.push_back(i);
  }

  for (long long i = 0; i < n; i++) {
    if (is_prime[a[i]] == true)
      primes.push_back(a[i]), used[a[i]] = true;
    else
      not_primes.push_back(a[i]);
  }

  for (long long i = 0; i < not_primes.size(); i++) {
    for (long long j = 0; j < small_prime.size(); j++) {
      if (not_primes[i] == 1)
        break;
      if (not_primes[i] % small_prime[j] != 0)
        continue;

      if (used[small_prime[j]] == true) {
        printf("setwise coprime\\n");
        return 0;
      }

      used[small_prime[j]] = true;

      while (not_primes[i] % small_prime[j] == 0) {
        not_primes[i] /= small_prime[j];
      }

      if (not_primes[i] > 1) {
        if (used[not_primes[i]] == true) {
          printf("setwise coprime\\n");
          return 0;
        }
        used[not_primes[i]] = true;
      }
    }
  }

  printf("pairwise coprime\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);

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

  long long g = a[0];
  for (long long i = 0; i < n; i++) {
    g = gcd(a[i], g);
  }

  if (g > 1) {
    printf("not coprime\\n");
    return 0;
  }

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

  set<long long> T;

  for (long long i = 0; i < n; i++) {

    set<long long>::iterator it;

    if (T.size() > 0) {
      for (it = T.begin(); it != T.end(); it++) {
        if (a[i] % *it == 0) {
          printf("setwise coprime\\n");
          return 0;
        }
      }
    }
    long long num = a[i];

    for (long long j = 2; j * j <= num + 1; j++) {
      if (num % j != 0)
        continue;

      while (num % j == 0) {
        if (T.find(j) == T.end())
          T.insert(j);
        num /= j;
      }
    }

    if (num != 1)
      T.insert(num);
  }
  printf("pairwise coprime\\n");
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iomanip>
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define mxn 1005003
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using namespace std;
vector<int> primes;
int put[mxn];
int cnt[mxn + 2] = {0};
void sieve() {
  for (int i = 2; i < mxn; i++) {
    if (!put[i]) {
      primes.pb(i);
      for (int j = 1; j * i < mxn; j++)
        put[i * j] = 1;
    }
  }
}
int main(void) {
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;
  int n, cr = 0, i, bad = 0;
  cin >> n;
  int a[n], g = 0;
  sieve();
  for (i = 0; i < n; i++) {
    cin >> a[i];
    g = __gcd(g, a[i]);
    cnt[a[i]]++;
  }
  for (auto x : primes) {
    cr = 0;
    for (i = 1; i * x <= mxn; i++)
      cr += cnt[i * x];
    if (cr > 1)
      bad = 1;
  }
  if (bad) {
    if (g == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  } else
    cout << "pairwise coprime";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define mxn 1000003
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using namespace std;
vector<int> primes;
int put[mxn];
int cnt[mxn];
void sieve() {
  for (int i = 2; i < mxn; i++) {
    if (!put[i]) {
      primes.pb(i);
      for (int j = 1; j * i <= mxn; j++)
        put[i * j] = 1;
    }
  }
}
int main(void) {
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;
  int n, cr = 0, i, bad = 0;
  cin >> n;
  int a[n], g = 0;
  sieve();
  for (i = 0; i < n; i++) {
    cin >> a[i];
    g = __gcd(g, a[i]);
  }
  for (i = 0; i < n; i++) {
    cr = 0;
    for (auto x : primes) {
      //	cout<<x<<" ";
      if (x > a[i])
        break;
      if (a[i] % x == 0)
        cnt[cr]++;
      if (cnt[cr] > 1)
        bad = 1;
      cr++;
    }
  }
  if (bad) {
    if (g == 1)
      cout << "setwise coprime";
    else
      cout << "not coprime";
  } else {
    cout << "pairwise coprime";
  }
}
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;
typedef long long int ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

bool used[1000005];

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

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  cin >> a[0];
  ll g = a[0];
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
    g = gcd(g, a[i]);
  }
  bool flag = true;
  for (int i = n - 1; i >= 0; --i) {
    for (auto p : divisor(a[i])) {
      if (p == 1)
        continue;
      if (used[p]) {
        flag = false;
        break;
      }
      used[p] = true;
    }
    if (!flag)
      break;
  }
  if (g == 1 && flag)
    cout << "pairwise coprime" << endl;
  else if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll g = a[n - 1];
  ll l = a[n - 1];
  bool flag = true;
  for (int i = n - 2; i >= 0; --i) {
    g = gcd(g, a[i]);
    if (gcd(a[i], l) != 1LL)
      flag = false;
    l = lcm(l, a[i]);
    while (l % 4 == 0) {
      l /= 2;
    }
    while (l % 9 == 0) {
      l /= 3;
    }
    while (l % 25 == 0) {
      l /= 5;
    }
    if (l > 1000000000000LL) {
      ll tmp = 1;
      for (auto x : prime_factor(l)) {
        tmp *= x.first;
      }
      l = tmp;
    }
  }
  if (g == 1LL && flag)
    cout << "pairwise coprime" << endl;
  else if (g == 1LL)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

string p = "pairwise coprime";
string s = "setwise coprime";
string n = "not coprime";

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

int gcd_arr(vector<int> &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<long long int, long long int> prime_factor(long long int n) {
  map<long long int, long long int> ret;
  for (long long int 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<int> A(N);
  map<int, int> prime;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    // map<ll, ll> tmp = prime_factor(A[i]);
    // for (auto tm : tmp) {
    // prime[tm.first] += 1;
    // }
  }

  vector<int> A_tmp = A;
  if (gcd_arr(A_tmp) != 1) {
    cout << n << endl;
    return 0;
  }

  for (int i = 0; i < N; i++) {
    map<ll, ll> tmp = prime_factor(A[i]);
    for (auto tm : tmp) {
      prime[tm.first] += 1;
      if (prime[tm.first] != 1) {
        cout << s << endl;
        return 0;
      }
    }
  }

  // for (auto pr : prime) {
  // if (pr.second != 1) {
  // cout << s << endl;
  // return 0;
  // }
  // }

  cout << p << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

string p = "pairwise coprime";
string s = "setwise coprime";
string n = "not coprime";

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

int gcd_arr(vector<int> &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<long long int, long long int> prime_factor(long long int n) {
  map<long long int, long long int> ret;
  for (long long int 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<int> A(N);
  map<int, int> prime;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    map<ll, ll> tmp = prime_factor(A[i]);
    for (auto tm : tmp) {
      prime[tm.first] += 1;
    }
  }

  if (gcd_arr(A) != 1) {
    cout << n << endl;
    return 0;
  }

  for (auto pr : prime) {
    if (pr.second != 1) {
      cout << s << endl;
      return 0;
    }
  }

  cout << p << endl;

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

#include <bits/stdc++.h>
#define ll long long
#define fr(i, n) for (ll i = 0; i < n; i++)
using namespace std;
const ll A = 1000005;
ll k[A], j[A];
ll n;
bool pairwise() {
  for (ll i = 2; i < A; i++) {
    int cnt = 0;

    for (ll ii = i; ii < A; ii += i) {
      cnt += j[ii];
    }
    if (cnt > 1) {
      return false;
    }
  }
  return true;
}

bool setwise() {
  ll gcd = k[0];
  for (ll i = 1; i < n; i++) {
    gcd = __gcd(k[i], gcd);
    {
      if (gcd == 1)
        return true;
    }
  }
  return false;
}

int main() {
  cin >> n;
  fr(i, n) cin >> k[i], j[k[i]]++;
  if (pairwise())
    cout << "pairwise coprime";
  else if (setwise())
    cout << "setwise coprime";
  else
    cout << "not coprime";
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bits/stdc++.h>
#include <chrono>
#include <climits>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;

/*
        time complexty
auto start = chrono::steady_clock::now();
    ............

auto endd = chrono::steady_clock::now();
auto dif =   endd- start;
cout << chrono::duration<double, milli>(dif).count() <<"ms"<<endl;

*/

int x, n, f1 = 1, f2 = 1;
map<int, int> mp;
int main() {

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {

    scanf("%d", &x);

    for (LL j = 2; j * j <= x; j++) {

      if (x % j == 0)
        mp[j] += 1;

      while (x % j == 0)
        x /= j;

      if (mp[j] > 1)
        f1 = 0;
      if (mp[j] >= n) {
        f2 = 0;
        break;
      }
    }
    if (x != 1)
      mp[x]++;

    if (mp[x] > 1)
      f1 = 0;
    if (mp[x] >= n) {
      f2 = 0;
      break;
    }
  }

  if (f1 || f2)
    puts(f1 ? "pairwise coprime\\n" : "setwise coprime\\n");

  else
    puts("not coprime\\n");

  return 0;
}