use std::io::Write; 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") }; } fn gcd(mut a: u64, mut b: u64) -> u64 { if a == 0 || b == 0 { return a + b; } let k = (a | b).trailing_zeros(); a >>= a.trailing_zeros(); b >>= b.trailing_zeros(); while a != b { if a < b { std::mem::swap(&mut a, &mut b); } a -= b; a >>= a.trailing_zeros(); } a << k } fn mul(mut a: u64, mut b: u64, m: u64) -> u64 { let mut x = 0; while a > 0 { if a % 2 > 0 { x += b; if x >= m { x -= m; } } a /= 2; b += b; if b >= m { b -= m; } } x } fn powmod(mut a: u64, mut e: u64, m: u64) -> u64 { let mut x = 1; while e > 0 { if e % 2 > 0 { x = mul(x, a, m); } a = mul(a, a, m); e /= 2; } x } fn is_prime(n: u64) -> bool { if n <= 3 { return n == 2 || n == 3; } else if n % 2 == 0 { return false; } let r = (n - 1).trailing_zeros(); let d = (n - 1) >> r; let mut test = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] .iter() .filter(|&&a| a <= n - 2); 'witness_loop: loop { if let Some(a) = test.next() { let mut x = powmod(a % n, d, n); if x == 1 || x == n - 1 { continue 'witness_loop; } let mut i = r; for i in 0..r { x = mul(x, x, n); if x == n - 1 { continue 'witness_loop; } } return false; } else { return 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(x) {1} else {0}; writeln!(out, "{} {}", x, ans).unwrap(); } } fn main() { run(); }