use std::cmp::*; use std::io::{Write, BufWriter}; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::>() }; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } fn factorize(mut x: i64) -> Vec<(i64, usize)> { let mut p = 2; let mut ans = vec![]; while p * p <= x { let mut e = 0; while x % p == 0 { x /= p; e += 1; } if e > 0 { ans.push((p, e)); } p += 1; } if x > 1 { ans.push((x, 1)); } ans } // Returns a table pr that satisfies pr[i] <=> i is prime (0 <= i < n). // Complexity: O(n log log n) fn is_primes_tbl(n: usize) -> Vec { if n <= 2 { return vec![false; n]; } let mut pr = vec![true; n]; pr[0] = false; pr[1] = false; for i in 2..n { if !pr[i] { continue; } for j in 2..(n - 1) / i { pr[i * j] = false; } } pr } fn main() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} input! { t: usize, x: [i64; t], } const W: usize = 1000; let pr = is_primes_tbl(W); for x in x { let pe = factorize(x); let mut mi = 0; for i in 2..W { if !pr[i] { continue; } if x % i as i64 == 0 { continue; } mi = i as i64; break; } for i in 2..mi { let mut orig = 1; let mut added = 1; let mut v = i; for &(p, e) in &pe { let mut f = 0; while v % p == 0 { f += 1; v /= p; } orig *= e + 1; added *= e + f + 1; } if v == 1 && added == 2 * orig { mi = i; break; } } puts!("{}\n", x * mi); } }