Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long, long long>

#define fastio()                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl "\n"

#define Debug(x) cout << (#x) << " >> " << (x) << endl

using namespace std;

ll fastpow(ll angka, ll pangkat, ll MOD) {
  ll res = 1;
  while (pangkat) {
    if (pangkat & 1)
      res = (res * angka) % MOD;
    angka = (angka * angka) % MOD;
    pangkat = pangkat >> 1;
  }
  return res;
}

ll fastpow(ll angka, ll pangkat) {
  ll res = 1;
  while (pangkat) {
    if (pangkat & 1)
      res = (res * angka);
    angka = (angka * angka);
    pangkat = pangkat >> 1;
  }
  return res;
}

ll gcd(ll angka1, ll angka2) {
  while (angka2) {
    swap(angka1, angka2);
    angka2 = angka2 % angka1;
  }
  return angka1;
}

ll lcm(ll angka1, ll angka2) { return (angka1 / gcd(angka1, angka2)) * angka2; }

const ll mod = 1000000007;

vector<int> spf;
void precompute_spf() {
  const int n = 2000000;

  spf.resize(n);
  int batas = sqrt(n);
  for (int i = 2; i < n; i++)
    spf[i] = i;
  for (int i = 2; i < n; i++) {
    if (spf[i] == i) {
      int j = i * i;
      while (j < n) {
        if (spf[j] == j)
          spf[j] = i;
        j += i;
      }
    }
  }

  //	for(int i=0;i<30;i++) cout<<i<<" "<<spf[i]<<endl;
}

void solve() {
  int n;
  cin >> n;

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

  bool isPairWise = true;
  unordered_map<int, int> um;
  for (auto x : v) {
    unordered_set<int> st;
    int val = x;
    while (val > 1) {
      st.insert(spf[val]);
      val = val / spf[val];
    }

    for (auto x : st) {
      um[x]++;
      if (um[x] > 1) {
        isPairWise = false;
        break;
      }
    }

    if (!isPairWise)
      break;
  }

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

  int cur = v[0];
  for (int i = 0; i < n; i++) {
    cur = gcd(cur, v[i]);
    //		cout<<cur<<endl;
  }
  if (cur == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

int main() {

  fastio();

  precompute_spf();

  int t = 1;
  //	cin>>t;

  for (int tt = 0; tt < t; tt++) {
    //		cout<<"Case "<<tt+1<<":\n";solve();
    solve();
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long, long long>

#define fastio()                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl "\n"

#define Debug(x) cout << (#x) << " >> " << (x) << endl

using namespace std;

ll fastpow(ll angka, ll pangkat, ll MOD) {
  ll res = 1;
  while (pangkat) {
    if (pangkat & 1)
      res = (res * angka) % MOD;
    angka = (angka * angka) % MOD;
    pangkat = pangkat >> 1;
  }
  return res;
}

ll fastpow(ll angka, ll pangkat) {
  ll res = 1;
  while (pangkat) {
    if (pangkat & 1)
      res = (res * angka);
    angka = (angka * angka);
    pangkat = pangkat >> 1;
  }
  return res;
}

ll gcd(ll angka1, ll angka2) {
  while (angka2) {
    swap(angka1, angka2);
    angka2 = angka2 % angka1;
  }
  return angka1;
}

ll lcm(ll angka1, ll angka2) { return (angka1 / gcd(angka1, angka2)) * angka2; }

const ll mod = 1000000007;

vector<int> spf;
void precompute_spf() {
  const int n = 2000000;

  spf.resize(n);
  int batas = sqrt(n);
  for (int i = 2; i < n; i++)
    spf[i] = i;
  for (int i = 2; i <= batas; i++) {
    if (spf[i] == i) {
      int j = i * i;
      while (j < n) {
        if (spf[j] == j)
          spf[j] = i;
        j += i;
      }
    }
  }

  //	for(int i=0;i<30;i++) cout<<i<<" "<<spf[i]<<endl;
}

void solve() {
  int n;
  cin >> n;

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

  bool isPairWise = true;
  unordered_map<int, int> um;
  for (auto x : v) {
    unordered_set<int> st;
    int val = x;
    while (val > 1) {
      st.insert(spf[val]);
      val = val / spf[val];
    }

    for (auto x : st) {
      um[x]++;
      if (um[x] > 1) {
        isPairWise = false;
        break;
      }
    }

    if (!isPairWise)
      break;
  }

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

  int cur = v[0];
  for (int i = 0; i < n; i++) {
    cur = gcd(cur, v[i]);
    //		cout<<cur<<endl;
  }
  if (cur == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}

int main() {

  fastio();

  precompute_spf();

  int t = 1;
  //	cin>>t;

  for (int tt = 0; tt < t; tt++) {
    //		cout<<"Case "<<tt+1<<":\n";solve();
    solve();
  }

  return 0;
}