Problem p02574 (C++) — buggy submission, verdict: Runtime Error

// g++ t.cpp -o t && t < p.txt
// d>p.txt&&t<p.txt&&t2<p.txt

#include <algorithm> // みんな大好きソートと二分探索
#include <bitset>
#include <ctime>
#include <functional> // 関数を変数に入れる子
#include <iostream>   // プログラムの耳と口
#include <map>        // setの妹 これまた優秀
#include <queue>      // きゅーちゃん、だいすき
#include <random>     // 乱択さん
#include <set>        // 値の取得・挿入・削除を高速に
#include <string>     // to_string
#include <vector>     // 超有能配列秘書

#define DB cerr << "D" << endl
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ll LINF = 1e18;
const double dINF = 1e18;
const ld ldINF = 1e18;
const double EPS = 1e-6;
template <typename T, typename U, typename O> void caut(T a, U b, O c) {
  cout << "(" << a << "," << b << "," << c << ") ";
}
template <typename T, typename U> void caut(T a, U b) {
  cout << "(" << a << "," << b << ") ";
}
template <typename T> void caut(T a) { cout << "(" << a << ") "; };
using P = pair<ll, ll>;
const ll M = 1e9 + 7;
ll mod_pow(ll x, ll a) {
  ll an = 1;
  while (a > 0) {
    if (a & 1)
      an = an * x % M;
    x = x * x % M;
    a >>= 1;
  }
  return an;
}
void add(ll &x, ll y) {
  x += y;
  x %= M;
};
void mul(ll &x, ll y) {
  x *= y;
  x %= M;
};
template <typename T, typename U> void chmax(T &x, U y) {
  if (x < y)
    x = y;
};
template <typename T, typename U> void chmin(T &x, U y) {
  if (x > y)
    x = y;
}
bool vaild(int x, int y, int hh, int ww) {
  return 0 <= x && x < hh && 0 <= y && y < ww;
}
int keta(ll a) {
  int res = 0;
  while (a > 0)
    res += a % 10, a /= 10;
  return res;
}
const int up[] = {1, -1, 0, 0}, lf[] = {0, 0, 1, -1};
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

// 1つめ：すべて素（レア）
// 2つめ：全体gcd
const int mmmmmmaaaaaaxxxxx = 1000100;
vector<int> v[mmmmmmaaaaaaxxxxx + 1];
bool b[mmmmmmaaaaaaxxxxx] = {};
int main() {
  for (int i = 2; i <= mmmmmmaaaaaaxxxxx; i++) {
    if (v[i].empty()) {
      for (int j = i; j <= mmmmmmaaaaaaxxxxx; j += i) {
        v[j].push_back(i);
      }
    }
  }

  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  bool pc = true;

  for (int i = 0; i < n; i++) {
    for (int x : v[a[i]]) {
      if (b[x])
        pc = false;
      b[x] = true;
    }
  }

  ll val = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    val = gcd(val, a[i]);
  }
  bool sc = val == 1;

  if (pc) {
    cout << "pairwise coprime" << endl;
  } else if (sc) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Error: 0

Fixed submission:

// g++ t.cpp -o t && t < p.txt
// d>p.txt&&t<p.txt&&t2<p.txt

#include <algorithm> // みんな大好きソートと二分探索
#include <bitset>
#include <ctime>
#include <functional> // 関数を変数に入れる子
#include <iostream>   // プログラムの耳と口
#include <map>        // setの妹 これまた優秀
#include <queue>      // きゅーちゃん、だいすき
#include <random>     // 乱択さん
#include <set>        // 値の取得・挿入・削除を高速に
#include <string>     // to_string
#include <vector>     // 超有能配列秘書

#define DB cerr << "D" << endl
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ll LINF = 1e18;
const double dINF = 1e18;
const ld ldINF = 1e18;
const double EPS = 1e-6;
template <typename T, typename U, typename O> void caut(T a, U b, O c) {
  cout << "(" << a << "," << b << "," << c << ") ";
}
template <typename T, typename U> void caut(T a, U b) {
  cout << "(" << a << "," << b << ") ";
}
template <typename T> void caut(T a) { cout << "(" << a << ") "; };
using P = pair<ll, ll>;
const ll M = 1e9 + 7;
ll mod_pow(ll x, ll a) {
  ll an = 1;
  while (a > 0) {
    if (a & 1)
      an = an * x % M;
    x = x * x % M;
    a >>= 1;
  }
  return an;
}
void add(ll &x, ll y) {
  x += y;
  x %= M;
};
void mul(ll &x, ll y) {
  x *= y;
  x %= M;
};
template <typename T, typename U> void chmax(T &x, U y) {
  if (x < y)
    x = y;
};
template <typename T, typename U> void chmin(T &x, U y) {
  if (x > y)
    x = y;
}
bool vaild(int x, int y, int hh, int ww) {
  return 0 <= x && x < hh && 0 <= y && y < ww;
}
int keta(ll a) {
  int res = 0;
  while (a > 0)
    res += a % 10, a /= 10;
  return res;
}
const int up[] = {1, -1, 0, 0}, lf[] = {0, 0, 1, -1};
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

// 1つめ：すべて素（レア）
// 2つめ：全体gcd

int main() {
  const int mmmmmmaaaaaaxxxxx = 100;
  vector<int> v[mmmmmmaaaaaaxxxxx + 1];
  for (int i = 2; i <= mmmmmmaaaaaaxxxxx; i++) {
    if (v[i].empty()) {
      for (int j = i; j <= mmmmmmaaaaaaxxxxx; j += i) {
        v[j].push_back(i);
      }
    }
  }

  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  bool b[mmmmmmaaaaaaxxxxx] = {};
  bool pc = true;

  for (int i = 0; i < n; i++) {
    // cout << a[i]<<" : ";
    for (int x : v[a[i]]) {
      // cout<<x<<" "<<b[x]<<endl;
      if (b[x])
        pc = false;
      b[x] = true;
    } // cout<<endl;
  }

  ll val = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    val = gcd(val, a[i]);
  }
  bool sc = val == 1;

  if (pc) {
    cout << "pairwise coprime" << endl;
  } else if (sc) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest