// -*- coding:utf-8-unix -*- pub fn modpow(mut b: u64, mut p: u64, n: u64) -> u64 { if p == 2 { return ((b as u128) * (b as u128) % (n as u128)) as u64; } let mut r = if (p & 1) == 0 { 1 } else { b }; loop { p >>= 1; if p == 0 { return r; } b = ((b as u128) * (b as u128) % (n as u128)) as u64; if (p & 1) != 0 { r = ((r as u128) * (b as u128) % (n as u128)) as u64; } } } pub fn miller_rabin(n: u64) -> bool { if n == 2 { return true; } if n < 2 || (n & 1) == 0 { return false; } let n1 = n - 1; let s = n1.trailing_zeros(); let d = n1 >> s; 'bases: for a in &[2,325,9375,28178,450775,9780504,1795265022] { let a = *a % n; if a == 0 { continue; } let mut t = modpow(a, d, n); if t == 1 || t == n1 { continue; } for _ in 1..s { t = modpow(t, 2, n); if t == n1 { continue 'bases; } } return false; } true } fn main() { use std::io::{BufRead,Write}; let start_time = std::time::Instant::now(); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} let input = std::io::stdin(); let mut lines = std::io::BufReader::new(input.lock()).lines(); let n: usize = lines.next().unwrap().unwrap().parse().unwrap(); for _ in 0..n { let x: u64 = lines.next().unwrap().unwrap().parse().unwrap(); puts!("{} {}\n", x, if miller_rabin(x) { "1" } else { "0" }); } eprint!("{}us\n", start_time.elapsed().as_micros()); }