Problem p02574 (C++) — buggy submission, verdict: Time Limit Exceeded


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define in(a)                                                                  \\
  ll a;                                                                        \\
  cin >> a;
#define in2(a, b)                                                              \\
  ll a, b;                                                                     \\
  cin >> a >> b;
#define in3(a, b, c)                                                           \\
  ll a, b, c;                                                                  \\
  cin >> a >> b >> c;
#define in4(a, b, c, d)                                                        \\
  ll a, b, c, d;                                                               \\
  cin >> a >> b >> c >> d;
#define in5(a, b, c, d, e)                                                     \\
  ll a, b, c, d, e;                                                            \\
  cin >> a >> b >> c >> d >> e;
#define lelo(b)                                                                \\
  for (auto &i : b)                                                            \\
    cin >> i;
#define ff first
#define ss second
#define call(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define show(x)                                                                \\
  for (auto t : x)                                                             \\
    cout << t << " ";
#define pb push_back
#define bhar(s, v) memset(s, v, sizeof(s))
#define endl "\\n"
#define ce(x) cout << x << "\\n";
#define nl cout << endl;
#define jaldi                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define dekh_lo ce("dekh_lo");
#define sz(x) (ll) x.size()
#define re return

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod = 1e9 + 7;
const ll N = 4e5 + 5;

/*


*/

ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  in(n);
  vi a(n);
  lelo(a);
  bool f = 0;

  ll to = gcd(a[0], a[1]);
  for (ll i = 2; i < sz(a); i++) {
    to = gcd(to, a[i]);
  }
  if (f == 0) {
    map<ll, ll> cnt;
    for (ll i = 0; i < sz(a); i++) {
      for (ll j = 2; j * j <= a[i]; j++) {
        if (a[i] % j == 0) {
          cnt[j]++;
          if (cnt[j] > 1) {
            f = 1;
            break;
          }
          while (a[i] % j == 0) {
            a[i] /= j;
          }
        }
      }
      if (f) {
        break;
      }
      if (a[i] > 1) {
        cnt[a[i]]++;
      }
    }
    for (auto i : cnt) {
      if (i.ss > 1) {
        f = 1;
        break;
      }
    }
  }
  if (f == 0) {
    ce("pairwise coprime");
    re 0;
  }
  if (to == 1) {
    ce("setwise coprime");
    re 0;
  }
  ce("not coprime");
}

/*


*/


Error: TLE

Fixed submission:


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define in(a)                                                                  \\
  ll a;                                                                        \\
  cin >> a;
#define in2(a, b)                                                              \\
  ll a, b;                                                                     \\
  cin >> a >> b;
#define in3(a, b, c)                                                           \\
  ll a, b, c;                                                                  \\
  cin >> a >> b >> c;
#define in4(a, b, c, d)                                                        \\
  ll a, b, c, d;                                                               \\
  cin >> a >> b >> c >> d;
#define in5(a, b, c, d, e)                                                     \\
  ll a, b, c, d, e;                                                            \\
  cin >> a >> b >> c >> d >> e;
#define lelo(b)                                                                \\
  for (auto &i : b)                                                            \\
    cin >> i;
#define ff first
#define ss second
#define call(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define show(x)                                                                \\
  for (auto t : x)                                                             \\
    cout << t << " ";
#define pb push_back
#define bhar(s, v) memset(s, v, sizeof(s))
#define endl "\\n"
#define ce(x) cout << x << "\\n";
#define nl cout << endl;
#define jaldi                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define dekh_lo ce("dekh_lo");
#define sz(x) (ll) x.size()
#define re return

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod = 1e9 + 7;
const ll N = 4e5 + 5;

/*


*/

ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int main() {
  in(n);
  vi a(n);
  lelo(a);
  ll to = gcd(a[0], a[1]);
  for (ll i = 2; i < sz(a); i++) {
    to = gcd(to, a[i]);
  }
  map<ll, ll> cnt;
  for (ll i = 0; i < sz(a); i++) {
    for (ll j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        cnt[j]++;
        while (a[i] % j == 0) {
          a[i] /= j;
        }
      }
    }
    if (a[i] > 1) {
      cnt[a[i]]++;
    }
  }
  bool f = 0;
  for (auto i : cnt) {
    if (i.ss > 1) {
      f = 1;
      break;
    }
  }
  if (f == 0) {
    ce("pairwise coprime");
    re 0;
  }
  if (to == 1) {
    ce("setwise coprime");
    re 0;
  }
  ce("not coprime");
}

/*


*/