use std::io; fn main() { let mut buf = String::new(); io::stdin().read_line(&mut buf).unwrap(); let n: i32 = buf.trim().parse().unwrap(); for _ in 0..n { let mut buf = String::new(); io::stdin().read_line(&mut buf).unwrap(); let i: i64 = buf.trim().parse().unwrap(); println!("{} {}", i, if miller_rabin(i) { 1 } else { 0 }); } } const BASES64: [i128; 7] = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]; #[no_mangle] pub extern "C" fn miller_rabin(n: i64) -> bool { if n < 2 { return false; } if (n & 1) == 0 { return n == 2; } let mut d = n - 1; let n = n as i128; let mut s = 0; while (d & 1) == 0 { s += 1; d >>= 1; } for a in BASES64.iter() { if *a >= n { break; } let mut c = true; let mut x = mod_pow(*a, d, n); if x == 1 { c = false; } for _ in 0..s { if x == n - 1 { c = false; } x = x * x % n; } if c { return false; } } return true; } fn mod_pow(mut x: i128, mut n: i64, m: i128) -> i128 { let mut res = 1i128; while n != 0 { if (n & 1) == 1 { res = res * x % m; } x = x * x % m; n >>= 1; } return res; }