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

#include "bits/stdc++.h"
#define rep(i, b) for (ll i = 0; i < b; i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
  cin >> first;
  IN(rest...);
  return;
}
#define SS(T, ...)                                                             \\
  T __VA_ARGS__;                                                               \\
  IN(__VA_ARGS__);
#define SV(type, c, n)                                                         \\
  vector<type> c(n);                                                           \\
  for (auto &i : c)                                                            \\
    cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void) {
  cout << endl;
  return 0;
}
template <class Head> int p(Head &&head) {
  cout << head;
  p();
  return 0;
}
template <class Head, class... Tail> int p(Head &&head, Tail &&...tail) {
  cout << head << " ";
  p(forward<Tail>(tail)...);
  return 0;
}
struct ProconInit {
  static constexpr bool AUTOFLUSH = false;
  ProconInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    if (AUTOFLUSH)
      cout << unitbuf;
  }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define vl vector<ll>
#define debug(x) cerr << #x << " " << x << '\\n';
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  return a.first + a.second > b.first + b.second;
}

map<int64_t, int> prime_factor(int64_t n) {
  map<int64_t, int> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}
vector<int> cnt(1000001);
signed main() {
  SS(ll, n);
  SV(ll, a, n);
  ll f = a[0];
  rep(i, n) { f = __gcd(f, a[i]); }
  ll sum = 0;
  set<ll> div_appear;
  rep(i, n) {
    for (auto p : prime_factor(a[i])) {
      cnt[p.first]++;
    }
  }
  if (*max_element(all(cnt)) <= 1) {
    p("pairwise coprime");
  } else if (f == 1) {
    p("setwise coprime");
  } else {
    p("not coprime");
  }
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#define rep(i, b) for (ll i = 0; i < b; i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
  cin >> first;
  IN(rest...);
  return;
}
#define SS(T, ...)                                                             \\
  T __VA_ARGS__;                                                               \\
  IN(__VA_ARGS__);
#define SV(type, c, n)                                                         \\
  vector<type> c(n);                                                           \\
  for (auto &i : c)                                                            \\
    cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void) {
  cout << endl;
  return 0;
}
template <class Head> int p(Head &&head) {
  cout << head;
  p();
  return 0;
}
template <class Head, class... Tail> int p(Head &&head, Tail &&...tail) {
  cout << head << " ";
  p(forward<Tail>(tail)...);
  return 0;
}
struct ProconInit {
  static constexpr bool AUTOFLUSH = false;
  ProconInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    if (AUTOFLUSH)
      cout << unitbuf;
  }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define vl vector<ll>
#define debug(x) cerr << #x << " " << x << '\\n';
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  return a.first + a.second > b.first + b.second;
}

vl divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  return ret;
}
vector<int> cnt(1000001);
signed main() {
  SS(ll, n);
  SV(ll, a, n);
  ll f = a[0];
  rep(i, n) { f = __gcd(f, a[i]); }
  ll sum = 0;
  set<ll> div_appear;
  rep(i, n) {
    for (auto p : divisor(a[i])) {
      if (p != 1)
        cnt[p]++;
    }
  }
  if (*max_element(all(cnt)) <= 1) {
    p("pairwise coprime");
  } else if (f == 1) {
    p("setwise coprime");
  } else {
    p("not coprime");
  }
}