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

/////////////////////////////////TEST CASES////////////////////////////////////
/*
 */
/////////////////////////////////////CODE//////////////////////////////////////
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp)                                                                \\
  ll inp;                                                                      \\
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve() {
  IN(n);
  vl v;
  map<ll, ll> m;
  FOR(i, 0, n) {
    IN(in);
    v.pb(in);
  }
  FOR(i, 0, n) {
    ll k = v[i];
    FOR(j, 2, sqrt(k) + 1) {
      if (k % j == 0)
        m[j]++;
      while (k % j == 0) {
        k /= j;
      }
    }
    if (k != 1)
      m[k]++;
  }
  ll f = 0, f1 = 0;
  for (auto i : m) {
    if (i.second == n)
      f = 1;
    if (i.second > 1)
      f1 = 1;
  }
  if (f == 1) {
    cout << "not coprime";
  } else if (f1 == 1) {
    cout << "setwise coprime";
  } else
    cout << "pairwise coprime";
}
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
}

Error: TLE

Fixed submission:

/////////////////////////////////TEST CASES////////////////////////////////////
/*
 */
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp)                                                                \\
  ll inp;                                                                      \\
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve() {
  IN(n);
  vl v;
  map<ll, ll> m;
  FOR(i, 0, n) {
    IN(in);
    v.pb(in);
  }
  FOR(i, 0, n) {
    ll k = v[i];
    FOR(j, 2, sqrt(k) + 1) {
      if (k % j == 0)
        m[j]++;
      while (k % j == 0) {
        k /= j;
      }
    }
    if (k != 1)
      m[k]++;
  }
  ll f = 0, f1 = 0;
  for (auto i : m) {
    if (i.second == n)
      f = 1;
    if (i.second > 1)
      f1 = 1;
  }
  if (f == 1) {
    cout << "not coprime";
  } else if (f1 == 1) {
    cout << "setwise coprime";
  } else
    cout << "pairwise coprime";
}
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
}