Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<pair<ll, ll>> prime_fact(ll x) {
  ll i = 2;
  vector<pair<ll, ll>> ans;
  while (i * i <= x) {
    ll tmp = 0;
    while (x % i == 0) {
      tmp++;
      x /= i;
    }
    if (tmp != 0) {
      ans.push_back(make_pair(i, tmp));
    }
    i++;
  }
  if (x != 1)
    ans.push_back(make_pair(x, 1));

  return ans;
}

ll gcd(ll x, ll y) {
  while (y > 0) {
    ll tmp = y;
    y = x % y;
    x = tmp;
  }
  return x;
}

int main() {
  ll N;
  cin >> N;
  v A(N);
  rep(i, 0, N) cin >> A[i];
  v used(100001, 0);
  bool p_ans = true;

  rep(i, 0, N) {
    vector<pair<ll, ll>> now;
    now = prime_fact(A[i]);
    rep(j, 0, now.size()) {
      if (used[now[j].first] >= 1)
        p_ans = false;
      else
        used[now[j].first]++;
      // cout<<now[j].first<<endl;
    }
    if (p_ans == false)
      break;
  }
  ll now = A[0];
  rep(i, 1, N) { now = gcd(now, A[i]); }

  ll s_ans = false;
  if (now == 1)
    s_ans = true;

  if (p_ans)
    cout << "pairwise coprime";
  else if (s_ans)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<pair<ll, ll>> prime_fact(ll x) {
  ll i = 2;
  vector<pair<ll, ll>> ans;
  while (i * i <= x) {
    ll tmp = 0;
    while (x % i == 0) {
      tmp++;
      x /= i;
    }
    if (tmp != 0) {
      ans.push_back(make_pair(i, tmp));
    }
    i++;
  }
  if (x != 1)
    ans.push_back(make_pair(x, 1));

  return ans;
}

ll gcd(ll x, ll y) {
  while (y > 0) {
    ll tmp = y;
    y = x % y;
    x = tmp;
  }
  return x;
}

int main() {
  ll N;
  cin >> N;
  v A(N);
  rep(i, 0, N) cin >> A[i];
  v used(1000001, 0);
  bool p_ans = true;

  rep(i, 0, N) {
    vector<pair<ll, ll>> now;
    now = prime_fact(A[i]);
    rep(j, 0, now.size()) {
      if (used[now[j].first] >= 1)
        p_ans = false;
      else
        used[now[j].first]++;
      // cout<<now[j].first<<endl;
    }
    if (p_ans == false)
      break;
  }
  ll now = A[0];
  rep(i, 1, N) { now = gcd(now, A[i]); }

  ll s_ans = false;
  if (now == 1)
    s_ans = true;

  if (p_ans)
    cout << "pairwise coprime";
  else if (s_ans)
    cout << "setwise coprime";
  else
    cout << "not coprime";
  return 0;
}