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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

// set<ll> st[1000001];

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll sp = a[0];
  for (int i = 0; i < n; ++i) {
    sp = gcd(sp, a[i]);
  }
  bool setwise = (sp == 1ll);
  vector<int> map(1000001);
  bool pairwise = true;
  for (int i = 0; i < n; ++i) {
    ll val = a[i];
    for (ll j = 2; j * j <= val; ++j) {
      int cnt = 0;
      while (val % j == 0) {
        cnt++;
        val /= j;
        if (map[j]) {
          pairwise = false;
        }
      }
      map[j] = cnt;
    }
    if (val != 1ll) {
      if (map[val]) {
        pairwise = false;
      }
      map[val] = 1;
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << '\\n';
  } else if (setwise) {
    cout << "setwise coprime" << '\\n';
  } else {
    cout << "not coprime" << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

set<ll> st[1000001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll sp = a[0];
  for (int i = 0; i < n; ++i) {
    sp = gcd(sp, a[i]);
  }
  bool setwise = (sp == 1ll);
  for (int i = 0; i < n; ++i) {
    ll val = a[i];
    for (ll j = 2; j * j <= val; ++j) {
      while (val % j == 0) {
        st[j].insert(i);
        val /= j;
      }
    }
    if (val != 1ll) {
      st[val].insert(i);
    }
  }
  bool pairwise = true;
  for (int i = 2; i <= 1000000; ++i) {
    if (1ll < st[i].size()) {
      pairwise = false;
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << '\\n';
  } else if (setwise) {
    cout << "setwise coprime" << '\\n';
  } else {
    cout << "not coprime" << '\\n';
  }
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define endl "\\n"
typedef long long ll;

#define mx 1000010
int dp[mx];
ll gcd(ll a, ll b) {
  // Write your code here
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

void solve() {
  int n;
  cin >> n;
  int arr[n];

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

  for (int i = 2; i < mx; i++) {
    if (!dp[i]) {
      for (int j = i; j < mx; j += i)
        dp[j] = i;
    }
  }
  dp[1] = 1;
  int ok = 1;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x = arr[i];

    while (x != dp[x]) {
      if (mp[dp[x]]) {
        if (mp[dp[x]] != i + 1)
          ok = 0;
      }

      mp[dp[x]] = i + 1;
      x /= dp[x];
    }
    if (x != 1) {
      if (mp[x] && mp[x] != i + 1)
        ok = 0;
      mp[x] = i + 1;
    }
  }
  if (ok) {
    cout << "pairwise coprime" << endl;
    return;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = gcd(ans, arr[i]);
  }
  if (ans == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define endl "\\n"
typedef long long ll;

#define mx 200002
int dp[mx];
void solve() {
  int n;
  cin >> n;
  int arr[n];

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

  for (int i = 2; i < mx; i++) {
    if (!dp[i]) {
      for (int j = i; j < mx; j += i)
        dp[j] = i;
    }
  }
  dp[1] = 1;
  int ok = 1;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x = arr[i];

    while (x != dp[x]) {
      if (mp[dp[x]]) {
        if (mp[dp[x]] != i + 1)
          ok = 0;
      }

      mp[dp[x]] = i + 1;
      x /= dp[x];
    }
    if (x != 1)
      mp[x] = i + 1;
  }
  if (ok) {
    cout << "pairwise coprime" << endl;
    return;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = __gcd(ans, arr[i]);
  }
  if (ans == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> lP;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
#define _GLIBCXX_DEBUG

int main() {
  int n;
  cin >> n;
  vector<int> a;
  rep(i, n) {
    int v;
    cin >> v;
    a.push_back(v);
  }

  vector<ll> prime(1000010, 0);
  rep(i, n) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j != 0)
        continue;
      while (a[i] % j == 0) {
        a[i] /= j;
      }
      prime[j]++;
    }
    if (a[i] != 1)
      prime[a[i]]++;
  }

  bool judge1 = true;
  bool judge2 = true;
  rep(i, 1000010) {
    if (prime[i] > 1)
      judge1 = false;
    if (prime[i] >= n)
      judge2 = false;
  }
  if (judge1 && judge2)
    cout << "pairwise coprime" << endl;
  else if (judge2)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> lP;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
#define _GLIBCXX_DEBUG

int main() {
  int n;
  cin >> n;
  vector<int> a;
  rep(i, n) {
    int v;
    cin >> v;
    a.push_back(v);
  }

  vector<ll> prime(100010, 0);
  rep(i, n) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j != 0)
        continue;
      while (a[i] % j == 0) {
        a[i] /= j;
      }
      prime[j]++;
    }
    if (a[i] != 1)
      prime[a[i]]++;
  }

  bool judge1 = true;
  bool judge2 = true;
  rep(i, 1010) {
    if (prime[i] > 1)
      judge1 = false;
    if (prime[i] >= n)
      judge2 = false;
  }
  if (judge1 && judge2)
    cout << "pairwise coprime" << endl;
  else if (judge2)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 1e6 + 10;

vector<int> D(MAX, INF);

void sieve() {

  D[1] = 1;

  for (int i = 2; i < MAX; i++) {
    if (D[i] != INF)
      continue;
    D[i] = i;
    for (int j = 2; j * i < MAX; j++)
      D[j * i] = min(D[i * j], i);
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  int N;
  cin >> N;

  vector<int> V(N);

  unordered_set<int> GG;

  vector<unordered_set<int>> DIV(N);

  bool pc = 1;
  int sc;

  int i = 0;
  for (auto &x : V) {
    cin >> x;

    if (!i)
      sc = x;
    else
      sc = __gcd(sc, x);

    while (x != 1) {
      DIV[i].insert(D[x]);
      x /= D[x];
    }

    for (auto y : DIV[i]) {
      if (GG.count(y))
        pc = 0;
      GG.insert(y);
    }

    i++;
  }

  if (pc) {
    cout << "pairwise coprime\\n";
    return 0;
  }

  cout << (sc != 1 ? "not coprime" : "setwise coprime") << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 1e6 + 10;

vector<int> D(MAX, INF);

void sieve() {

  D[1] = 1;

  for (int i = 2; i < MAX; i++) {
    if (D[i] != INF)
      continue;
    D[i] = i;
    for (int j = 2; j * i < MAX; j++)
      D[j * i] = min(D[i * j], i);
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  int N;
  cin >> N;

  vector<int> V(N);

  unordered_set<int> GG;

  vector<unordered_set<int>> DIV(N);

  bool pc = 1;

  int i = 0;
  for (auto &x : V) {
    cin >> x;
    while (x != 1) {
      DIV[i].insert(D[x]);
      x /= D[x];
    }

    for (auto y : DIV[i]) {
      if (GG.count(y))
        pc = 0;
      GG.insert(y);
    }

    i++;
  }

  if (pc) {
    cout << "pairwise coprime\\n";
    return 0;
  }

  bool notsc = 0;

  for (auto x : GG) {
    bool inall = 1;
    for (int i = 0; i < N; i++)
      inall &= (DIV[i].count(x));
    notsc |= inall;
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_1 (i, j, n) for (int i = j; i < n; i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
  int n;
  cin >> n;
  map<int, int> insu;
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    int x = a[i];
    for (int j = 2; j <= sqrt(x); j++) {
      if (x % j == 0)
        insu[j]++;
      while (x % j == 0) {
        x /= j;
      }
    }
    if (x > 1)
      insu[x]++;
  }
  bool judge0 = true, judge1 = false;
  for (auto x : insu) {
    if (x.second > 1)
      judge0 = false;
  }
  if (judge0) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  for (auto x : insu) {
    if (x.second == n)
      judge1 = true;
  }
  if (judge1) {
    cout << "not coprime" << endl;
    return 0;
  }
  cout << "setwise coprime" << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_1 (i, j, n) for (int i = j; i < n; i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int x = max(n + 1, 1001);
  bool setjudge = false;
  rep(i, x) {
    if (i < 2)
      continue;
    bool judge = false;
    rep(j, n) {
      if (judge && a[j] % i == 0) {
        setjudge = true;
        break;
      } else if (a[j] % i == 0)
        judge = true;
    }
  }
  if (setjudge) {
    rep(i, x) {
      if (i < 2)
        continue;
      bool judge = true;
      rep(j, n) {
        if (a[j] % i != 0)
          judge = false;
      }
      if (judge) {
        cout << "not coprime" << endl;
        return 0;
      }
    }
    cout << "setwise coprime" << endl;
  } else {
    cout << "pairwise coprime" << endl;
  }
}
Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int nax = 1e6 + 7;

int lpf[nax], mobius[nax];

void least_prime_factor() {
  for (int i = 2; i < nax; i++) {
    if (!lpf[i]) {
      for (int j = i; j < nax; j += i) {
        if (!lpf[j]) {
          lpf[j] = i;
        }
      }
    }
  }
  return;
}
void mob() {
  for (int i = 1; i < nax; i++) {
    if (i == 1) {
      mobius[i] = 1;
    } else {
      if (lpf[i / lpf[i]] == lpf[i]) {
        mobius[i] = 0;
      } else {
        mobius[i] = -1 * mobius[i / lpf[i]];
      }
    }
  }
  return;
}
int gp(int a[], int n) {
  int maxi = 0;
  int fre[nax] = {0};
  for (int i = 0; i < n; i++) {
    fre[a[i]]++;
    maxi = max(a[i], maxi);
  }
  least_prime_factor();
  mob();
  int ans = 0;
  for (int i = 1; i <= maxi; i++) {
    if (!mobius[i]) {
      continue;
    }
    int temp = 0;
    for (int j = i; j <= maxi; j += i) {
      temp += fre[j];
    }
    ans += temp * (temp - 1) / 2 * mobius[i];
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  int pairs = gp(a, n);
  if (pairs == (n * (n - 1)) / 2) {
    cout << "pairwise coprime\\n";
    return 0;
  }
  if (gcd == 1) {
    cout << "setwise coprime\\n";
    return 0;
  }
  cout << "not coprime\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int nax = 2e5 + 7;

int lpf[nax], mobius[nax];

void least_prime_factor() {
  for (int i = 2; i < nax; i++) {
    if (!lpf[i]) {
      for (int j = i; j < nax; j += i) {
        if (!lpf[j]) {
          lpf[j] = i;
        }
      }
    }
  }
  return;
}
void mob() {
  for (int i = 1; i < nax; i++) {
    if (i == 1) {
      mobius[i] = 1;
    } else {
      if (lpf[i / lpf[i]] == lpf[i]) {
        mobius[i] = 0;
      } else {
        mobius[i] = -1 * mobius[i / lpf[i]];
      }
    }
  }
  return;
}
int gp(int a[], int n) {
  int maxi = 0;
  int fre[nax] = {0};
  for (int i = 0; i < n; i++) {
    fre[a[i]]++;
    maxi = max(a[i], maxi);
  }
  least_prime_factor();
  mob();
  int ans = 0;
  for (int i = 1; i <= maxi; i++) {
    if (!mobius[i]) {
      continue;
    }
    int temp = 0;
    for (int j = i; j <= maxi; j += i) {
      temp += fre[j];
    }
    ans += temp * (temp - 1) / 2 * mobius[i];
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    gcd = __gcd(gcd, a[i]);
  }
  int pairs = gp(a, n);
  if (pairs == (n * (n - 1)) / 2) {
    cout << "pairwise coprime\\n";
    return 0;
  }
  if (gcd == 1) {
    cout << "setwise coprime\\n";
    return 0;
  }
  cout << "not coprime\\n";
  return 0;
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sort(v) sort(v.begin(), v.end())
#define pb push_back
vector<ll> sv;
ll ar[1000000 + 9] = {0};
void seiv() {
  ll n = 1000000, i, j;
  ar[1] = 1;
  for (i = 4; i <= n; i += 2)
    ar[i] = 1;
  for (i = 3; i <= n; i += 2) {
    if (ar[i] == 0) {
      for (j = i * i; j <= n; j += i * 2)
        ar[j] = 1;
    }
  }
  for (i = 2; i <= n; i++) {
    if (ar[i] == 0)
      sv.pb(i);
  }
}
int main() {
  seiv();
  map<ll, ll> m;
  ll a, b, c, d, e, i, j, k, l;
  vector<ll> v;
  cin >> a;
  k = 1;
  for (i = 1; i <= a; i++) {
    cin >> b;
    v.pb(b);

    k = max(k, m[b]);
    if (i == 1)
      c = __gcd(b, b);
    else
      c = __gcd(c, b);
  }
  if (c != 1) {
    cout << "not coprime\\n";
    return 0;
  } else {
    c = 0;
    d = 0;

    m.clear();
    c = 0;
    for (i = 0; i < v.size(); i++) {
      b = v[i];
      for (j = 0; j < sv.size(); j++) {
        if (sv[j] > b)
          break;
        if (ar[b] == 0) {
          m[b]++;
          c = max(c, m[b]);
          b = 0;
          break;
        }
        if (b % sv[j] == 0) {
          m[sv[j]]++;
          c = max(c, m[sv[j]]);
          while (b % sv[j] == 0) {
            b /= sv[j];
          }
        }
      }
      if (b > 1) {
        m[b]++;
        m[1] = 0;
        c = max(c, m[b]);
        cout << b << endl;
      }
    }
  }
  if (c > 1)
    cout << "setwise coprime\\n";
  else
    cout << "pairwise coprime\\n";
  // cout<<m[7]<<" "<<c;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sort(v) sort(v.begin(), v.end())
#define pb push_back
vector<ll> sv;
ll ar[1000000 + 9] = {0};
void seiv() {
  ll n = 1000, i, j;
  ar[1] = 1;
  for (i = 4; i <= n; i += 2)
    ar[i] = 1;
  for (i = 3; i <= n; i += 2) {
    if (ar[i] == 0) {
      for (j = i * i; j <= n; j += i * 2)
        ar[j] = 1;
    }
  }
  for (i = 2; i <= n; i++) {
    if (ar[i] == 0)
      sv.pb(i);
  }
}
int main() {
  seiv();
  map<ll, ll> m;
  ll a, b, c, d, e, i, j, k, l;
  vector<ll> v;
  cin >> a;
  k = 1;
  for (i = 1; i <= a; i++) {
    cin >> b;
    v.pb(b);

    k = max(k, m[b]);
    if (i == 1)
      c = __gcd(b, b);
    else
      c = __gcd(c, b);
  }
  if (c != 1) {
    cout << "not coprime\\n";
    return 0;
  } else {
    c = 0;
    d = 0;

    m.clear();
    c = 0;
    for (i = 0; i < v.size(); i++) {
      b = v[i];
      for (j = 0; j < sv.size(); j++) {
        if (sv[j] > b)
          break;
        if (b % sv[j] == 0) {
          m[sv[j]]++;
          c = max(c, m[sv[j]]);
          while (b % sv[j] == 0) {
            b /= sv[j];
          }
        }
      }
      if (b > 1)
        m[b]++;
      m[1] = 0;
      c = max(c, m[b]);
    }
  }
  if (c > 1)
    cout << "setwise coprime\\n";
  else
    cout << "pairwise coprime\\n";
}
Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define repr(e, x) for (auto &e : x)
using namespace std;
typedef long long ll;
typedef long double ld;
// typedef pair<int,int> P;
int const INF = 1001001001;
ll const LINF = 1001001001001001001;
ll const MOD = 1000000007;

template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int MAX = 1000000;
int N;
int A[1000000];

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

  vector<int> cnt(MAX + 1);
  rep(i, N) cnt[A[i]]++;

  bool flag = true;
  for (int i = 2; i <= MAX; i++) {
    int sum = 0;
    for (int j = i; j <= MAX; j += i) {
      sum += cnt[j];
    }
    if (sum > 1) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = 0;
  rep(i, N) g = gcd(g, A[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define repr(e, x) for (auto &e : x)
using namespace std;
typedef long long ll;
typedef long double ld;
// typedef pair<int,int> P;
int const INF = 1001001001;
ll const LINF = 1001001001001001001;
ll const MOD = 1000000007;

template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

ll N;
ll A[1000000];

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

  ll maxi = 0;
  rep(i, N) maxi = max(maxi, A[i]);

  vector<ll> D(maxi + 1);
  for (int i = 2; i <= maxi; i++) {
    ll k = 2;
    while (i % k != 0)
      k++;
    D[i] = k;
  }

  vector<ll> cnt(1001);
  rep(i, N) {
    ll a = A[i];
    while (a > 1) {
      ll m = D[a];
      while (a % m == 0)
        a /= m;
      cnt[m]++;
    }
  }
  bool flag = true;
  rep(i, 1000) {
    if (cnt[i] > 1)
      flag = false;
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll g = 0;
  rep(i, N) { g = gcd(g, A[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>
using namespace std;

typedef unsigned long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
#define int ll
#define MOD 1000000007
#define maxn 1000010

int num[maxn], A[maxn], N;

int32_t main() {
  cin >> N;
  FOR(i, 1, N) cin >> A[i];

  FOR(i, 0, maxn - 1) num[i] = 0;

  FOR(i, 1, N) {
    int x = A[i];
    if (x % 2 == 0)
      num[2]++;
    while (x % 2 == 0)
      x /= 2;

    for (int i = 3; i <= sqrt(x); i += 2) {
      if (x % i == 0)
        num[i]++;
      while (x % i == 0)
        x /= i;
    }
    if (x > 2)
      num[x]++;
  }

  bool pairwise = 1;
  FOR(i, 2, maxn - 1) if (num[i] > 1) { pairwise = 0; }

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

  int cur = A[1];
  FOR(i, 2, N) cur = __gcd(cur, A[i]);

  if (cur == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}


Error: TLE

Fixed submission:

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

typedef unsigned long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
#define int ll
#define MOD 1000000007
#define maxn 1000010

int num[maxn], A[maxn], N;

int32_t main() {
  cin >> N;
  FOR(i, 1, N) cin >> A[i];

  FOR(i, 0, maxn - 1) num[i] = 0;

  FOR(i, 1, N) {
    int cur = A[i];
    for (int j = 2; cur > 1; j++) {
      if (cur % j == 0)
        num[j]++;
      while (cur % j == 0)
        cur /= j;
    }
  }

  bool pairwise = 1;
  FOR(i, 2, maxn - 1) if (num[i] > 1) { pairwise = 0; }

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

  int cur = A[1];
  FOR(i, 2, N) cur = __gcd(cur, A[i]);

  if (cur == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}