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

#include <stdio.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
const int MAX = 1e6;
static inline int IN(void) {
  int x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
static inline int GCD(int a, int b) { return !b ? a : GCD(b, a % b); }
typedef struct {
  int SPF[1000001], Primes[168], sz;
} Template;
Template P;
static inline void ready(void) {
  *P.SPF = 1, *P.Primes = 2, P.sz = 1;
  rep(i, MAX / 2) P.SPF[2 * (i + 1)] = 2,
                                 P.SPF[2 * (i + 1) - 1] = 2 * (i + 1) - 1;
  rep(i, MAX / 2 - 1) {
    int x = 2 * (i + 1) + 1;
    if (P.SPF[x] == x) {
      P.Primes[P.sz++] = x;
    }
    if (x * x > MAX)
      break;
    rep(j, P.sz) {
      if (P.Primes[j] <= P.SPF[x] && x * P.Primes[j] <= MAX)
        P.SPF[x * P.Primes[j]] = P.Primes[j];
      else
        break;
    }
  }
}
const char common[] = "not coprime", disjoint[] = "pairwise coprime",
           several[] = "setwise coprime";
int vol = 0, esc[1000000];
static inline int Divise(int x) {
  if (!x) {
    return 0;
  }
  rep(i, P.sz) {
    if (P.Primes[i] * P.Primes[i] > x)
      break;
    if (x % P.Primes[i] == 0) {
      if (esc[P.Primes[i] - 1])
        return 0;
      esc[P.Primes[i] - 1] = 1;
      while (x % P.Primes[i] == 0 && x)
        x /= P.Primes[i];
    }
  }
  if (x > 1) {
    if (esc[x - 1])
      return 0;
    esc[x - 1] = 1;
  }
  return 1;
}
int main(void) {
  int N = IN(), A = 0, flag = 0, g = 0;
  ready();
  rep(i, N) {
    A = IN();
    g = GCD(g, A);
    if (i && g != 1) {
      flag = 1;
    }
    if (!Divise(A)) {
      flag = 1;
    }
  }
  if (g > 1)
    return puts(common), 0;
  if (flag)
    return puts(several), 0;
  else
    return puts(disjoint), 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
const int MOD = 1e9 + 7, MAX = 1e6;
static inline int IN(void) {
  int x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
static inline int GCD(int a, int b) { return !b ? a : GCD(b, a % b); }
typedef struct {
  int SPF[1000001], Primes[168], sz;
} Template;
Template P;
static inline void ready(void) {
  *P.SPF = 1, *P.Primes = 2, P.sz = 1;
  rep(i, MAX / 2) P.SPF[2 * (i + 1)] = 2,
                                 P.SPF[2 * (i + 1) - 1] = 2 * (i + 1) - 1;
  rep(i, MAX / 2 - 1) {
    int x = 2 * (i + 1) + 1;
    if (P.SPF[x] == x) {
      P.Primes[P.sz++] = x;
    }
    if (x * x > MAX)
      break;
    rep(j, P.sz) {
      if (P.Primes[j] <= P.SPF[x] && x * P.Primes[j] <= MAX)
        P.SPF[x * P.Primes[j]] = P.Primes[j];
      else
        break;
    }
  }
}
const char common[] = "not coprime", disjoint[] = "pairwise coprime",
           partial[] = "setwise coprime";
int vol = 0, esc[1000][2];
static inline int Divise(int x) {
  if (!x)
    return 0;
  while (x > 1) {
    rep(i, vol) {
      if (esc[i][0] == P.SPF[x] && esc[i][1])
        return 0;
    }
    esc[vol][0] = P.SPF[x], esc[vol++][1] = 1;
    x /= P.Primes[x];
  }
  return 1;
}
int main(void) {
  int N = IN(), A = 0, g = 0, flag = 0;
  ready();
  rep(i, N) {
    A = IN();
    g = GCD(g, A);
    if (!Divise(A)) {
      flag = 1;
    }
  }
  if (g > 1)
    return puts(common), 0;
  if (flag)
    return puts(partial), 0;
  return puts(disjoint), 0;
}