Problem:
Score : 500 points

Problem Statement

We have N integers. The i-th number is A_i.

\{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.

\{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.

Determine if \{A_i\} is pairwise coprime, setwise coprime, or neither.

Here, GCD(\ldots) denotes greatest common divisor.

Constraints

2 \leq N \leq 10^6

1 \leq A_i\leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

If \{A_i\} is pairwise coprime, print pairwise coprime; if \{A_i\} is setwise coprime, print setwise coprime; if neither, print not coprime.

Sample Input 1

3
3 4 5

Sample Output 1

pairwise coprime

GCD(3,4)=GCD(3,5)=GCD(4,5)=1, so they are pairwise coprime.

Sample Input 2

3
6 10 15

Sample Output 2

setwise coprime

Since GCD(6,10)=2, they are not pairwise coprime. However, since GCD(6,10,15)=1, they are setwise coprime.

Sample Input 3

3
6 10 16

Sample Output 3

not coprime

GCD(6,10,16)=2, so they are neither pairwise coprime nor setwise coprime.

Solution in C (GCC 9.2.1) (judge verdict: Wrong Answer)

// SPDX-License-Identifier: X11
// 2020-08-31
// Coprime (500pt)

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#define MAX 1000005

bool *erato(uint_least32_t bound);

int main() {
  uint_least32_t N;
  scanf("%u\n", &N);

  bool *P = erato(MAX);
  uint_least32_t *Ap = calloc(MAX, sizeof(uint_least32_t));

  bool set = true;
  bool pair = true;

  uint_least8_t s;
  uint_least32_t A, i, j;
  for (i = 0; i < N - 1; i++) {
    scanf("%u", &A);

    if (A == 1) {
      continue;
    }
    else if (P[A]) {
    if (Ap[A])
      pair = false;
    Ap[A]++;

    continue;
    }

    if (!(A & 1)) {
      if (Ap[2])
        pair = false;
      Ap[2]++;

      while (!(A & 1))
        A >>= 1;

      if (A == 1) {
        continue;
      }
      else if (P[A]) {
        if (Ap[A])
          pair = false;
        Ap[A]++;

        continue;
      }
    }

    if (!(A % 3)) {
      if (Ap[3])
        pair = false;
      Ap[3]++;

      while (!(A % 3))
        A /= 3;

      if (A == 1) {
        continue;
      }
      else if (P[A]) {
        if (Ap[A])
          pair = false;
        Ap[A]++;

        continue;
      }
    }

    for (j = 5, s = 2; j * j <= A; j += s, s = 6 - s)
      if (!(A % j)) {
        if (Ap[j])
          pair = false;
        Ap[j]++;

        while (!(A % j))
          A /= j;

        if (A == 1) {
          break;
        }
        else if (P[A]) {
          if (Ap[A])
            pair = false;
          Ap[A]++;

          break;
        }
      }
  }

  scanf("%u", &A);

  if (P[A]) {
    if (Ap[A])
      pair = false;
    Ap[A]++;

    if (Ap[A] == N)
      set = false;
  }

  if (!P[A] && !(A & 1)) {
    if (Ap[2])
      pair = false;
    Ap[2]++;

    if (Ap[2] == N)
      set = false;

    while (!(A & 1))
      A >>= 1;

    if (P[A]) {
      if (Ap[A])
        pair = false;
      Ap[A]++;

      if (Ap[A] == N)
        set = false;
    }
  }

  if (!P[A] && !(A % 3)) {
    if (Ap[3])
      pair = false;
    Ap[3]++;

    if (Ap[3] == N)
      set = false;

    while (!(A % 3))
      A /= 3;

    if (P[A]) {
      if (Ap[A])
        pair = false;
      Ap[A]++;

      if (Ap[A] == N)
        set = false;
    }
  }

  if(!P[A])
    for (i = 5, s = 2; i * i <= A; i += s, s = 6 - s)
      if (!(A % j)) {
        if (Ap[j])
          pair = false;
        Ap[j]++;

        if (Ap[j] == N)
          set = false;

        while (!(A % j))
          A /= j;

        if (A == 1) {
          break;
        }
        else if (P[A]) {
          if (Ap[A])
            pair = false;
          Ap[A]++;

          if (Ap[A] == N)
            set = false;

          break;
        }
      }

  if (pair)
    printf("pairwise coprime\n");
  else if (set)
    printf("setwise coprime\n");
  else
    printf("not coprime\n");

  free(P);
  free(Ap);
}

bool *erato(uint_least32_t bound) {
  if (!bound)
    return NULL;

  bool *array = calloc(bound, sizeof(bool));
  uint_least32_t i,j;
  uint_least8_t s,ss;

  if (bound < 3)
    return array;
  array[2] = true;

  if (bound < 4)
    return array;
  array[3] = true;

  if (bound < 5)
    return array;

  for (i = 5, s = 2; i < bound; i += s, s = 6 - s)
    array[i] = true;

  for (i = 5, s = 2; i < bound; i += s, s = 6 - s)
    if (array[i])
      for (j = i, ss = s; i * j < bound; j += ss, ss = 6 - ss)
        array[i * j] = false;

  return array;
}