//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ここまで use std::io::Write; fn mod_pow(r: u64, mut n: u64, p: u64) -> u64 { let mut t: u128 = 1; let mut s: u128 = (r % p) as u128; let p = p as u128; while n > 0 { if (n & 1) == 1 { t = t * s % p; } s = s * s % p; n >>= 1; } t as u64 } fn is_prime_miller(n: u64) -> bool { if n <= 1 { return false; } else if n <= 3 { return true; } else if n % 2 == 0 { return false; } let mut d = n - 1; let mut s = 0; while d % 2 == 0 { d /= 2; s += 1; } const B: [u64; 12] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]; for &b in &B { if b >= n { break; } let mut a = mod_pow(b, d, n); if a == 1 { continue; } let mut i = 0; while i < s && a != n - 1 { i += 1; a = (a as u128 * a as u128 % n as u128) as u64; } if i >= s { return false; } } true } fn run() { let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); input! { n: usize, x: [u64; n], } for x in x { let ans = if is_prime_miller(x) {1} else {0}; writeln!(out, "{} {}", x, ans).unwrap(); } } fn main() { run(); }