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 Rust (1.42.0) (judge verdict: Wrong Answer)

//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        a: [usize;n]
    }

    let mut a = a;
    a.sort();

    let dead = eratosthenes(1000001);
    let mut map = HashMap::new();

    let mut coprime = true;

    for i in 0..a.len() {
        if dead[a[i]] != 0 {
            let count = map.entry(dead[a[i]]).or_insert(0);
            *count += 1;
            if *count > 1 {
                coprime = false;
                //println!("{} {} {}", a[i], count, dead[a[i]]);
                break;
            }
        }
    }

    if coprime {
        println!("pairwise coprime");
        return;
    }

    let mut gcd_num = a[0];
    for i in 1..n {
        gcd_num = gcd(gcd_num, a[i]);
    }

    if gcd_num == 1 {
        println!("setwise coprime");
        return;
    }

    println!("not coprime");
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet

// 最大公約数
fn gcd(a: usize, b: usize) -> usize {
    let mut aa: usize = if a > b { a } else { b };
    let mut bb: usize = if a > b { b } else { a };
    while bb != 0 {
        let tmp = bb;
        bb = aa % tmp;
        aa = tmp;
    }
    return aa;
}

// エラストテネスの篩
fn eratosthenes(n: usize) -> Vec<usize> {
    let mut prime_list: Vec<usize> = Vec::new();
    let mut search_list: VecDeque<usize> = VecDeque::new();

    let mut dead = vec![0; 1000002];
    let n_sqrt = (n as f64).sqrt() as usize;

    for i in 2..n + 1 {
        search_list.push_back(i);
    }

    while true {
        let new_prime = match search_list.pop_front() {
            Some(x) => x,
            None => panic!(),
        };

        dead[new_prime] = new_prime;

        prime_list.push(new_prime);

        // search_listからの除外
        search_list = search_list
            .iter()
            .filter(|x| {
                if **x % new_prime != 0 {
                    true
                } else {
                    if dead[**x] == 0 {
                        dead[**x] = new_prime
                    }
                    false
                }
            })
            .map(|x| *x)
            .collect();

        if search_list.front() == None {
            break;
        }

        if search_list.front().unwrap() > &n_sqrt {
            break;
        }
    }

    while search_list.len() > 0 {
        prime_list.push(search_list.pop_front().unwrap());
    }

    return dead;
}