#[allow(dead_code)] fn solve(read: &mut snio::Reader>) { let n = read.i64(); for _ in 0..n { let f = read.u128(); println!("{} {}",f, if miller_rabin(f,100) {1} else {0}); } } //use proconio::input; fn main() { let t = std::io::stdin(); let mut read = snio::Reader::new(t.lock()); let n = 1; for _ in 0..n { solve(&mut read); } } #[allow(dead_code)] pub mod snio { pub struct Reader { reader: R, buf: std::collections::VecDeque, } impl Reader { pub fn new(reader: R) -> Self { Self { reader, buf: std::collections::VecDeque::new(), } } fn load(&mut self) { while self.buf.is_empty() { let mut s = String::new(); let length = self.reader.read_line(&mut s).unwrap(); if length == 0 { break; } self.buf.extend(s.split_whitespace().map(|s| s.to_owned())); } } pub fn string(&mut self) -> String { self.load(); self.buf.pop_front().unwrap_or_else(|| panic!("input ended")) } pub fn char(&mut self) -> char { let string = self.string(); let mut chars = string.chars(); let res = chars.next().unwrap(); assert!(chars.next().is_none(), "invalid input!"); res } pub fn chars(&mut self) -> Vec { self.read::().chars().collect() } pub fn read(&mut self) -> T where ::Err: ::std::fmt::Debug, { self.string().parse::().expect("Failed to parse the input.") } } macro_rules! definition_of_reader_of_numbers { ($($ty:tt,)*) => { impl Reader { $( #[inline] pub fn $ty (&mut self) -> $ty { self.read::<$ty>() } )* } } } definition_of_reader_of_numbers! { u8,u16,u32,u64,usize, i8,i16,i32,i64,isize,u128, f32,f64, } } const INF:i64 = 1i64 << 60; static mut XORSHIFT1:u128 = 123456789; static mut XORSHIFT2:u128 = 362436069; static mut XORSHIFT3:u128 = 521288629; static mut XORSHIFT4:u128 = 88675123; fn xorshift() -> u128 { unsafe { let mut t = 0; t = XORSHIFT1^(XORSHIFT1 << 11u128); XORSHIFT1 = XORSHIFT2; XORSHIFT2 = XORSHIFT3; XORSHIFT3 = XORSHIFT4; XORSHIFT4 = (XORSHIFT4 ^ (XORSHIFT4 >> 19u128)) ^ (t ^ (t >> 8u128)); t } } fn witness(n: u128, a: u128) -> bool { let mut t = 0; let mut u = n - 1; while u & 1u128 == 0 { t += 1; u >>= 1; } let mut x:u128 = modpow(a % n, u, n); for _ in 0..t { let b = x * x % n; if b == 1 { if b != 1 && b != n - 1 { return true; } else { return false; } } x = b; } true } fn miller_rabin(n: u128, times: i64) -> bool { if n == 1 { return false; } if n % 2 == 0 { return n == 2; } for _ in 0..times { //let mut a = rand::thread_rng().gen_range(1,n); let mut a = xorshift() % n; while a == 0 { a = xorshift() % n; } if witness(n, a) { return false; } } true } fn modpow(_x: u128, _n: u128, modulo: u128) -> u128 { if _n == 0 { return 1; } if _n % 2 == 0 { let t = modpow(_x, _n / 2, modulo); return t * t % modulo; } _x % modulo * modpow(_x, _n - 1, modulo) % modulo }