// floor(a ^ (1 / k)) pub fn kth_root(a: u64, k: u64) -> u64 { assert!(k > 0); if a == 0 { return 0; } if k >= 64 { return 1; } if k == 1 { return a; } let valid = |x: u64| -> bool { let mut t = x; for _ in 1..k { let (val, ok) = t.overflowing_mul(x); if !(!ok && val <= a) { return false; } t = val; } true }; let mut ok = 1; let mut ng = 2; while valid(ng) { ok = ng; ng *= 2; } while ng - ok > 1 { let mid = ok + (ng - ok) / 2; if valid(mid) { ok = mid; } else { ng = mid; } } ok } // ---------- begin binary_gcd ---------- pub fn binary_gcd(a: u64, b: u64) -> u64 { if a == 0 || b == 0 { return a + b; } let x = a.trailing_zeros(); let y = b.trailing_zeros(); let mut a = a >> x; let mut b = b >> y; while a != b { let x = (a ^ b).trailing_zeros(); if a < b { std::mem::swap(&mut a, &mut b); } a = (a - b) >> x; } a << x.min(y) } // ---------- end binary_gcd ---------- // ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { self.it.next().unwrap().parse::().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec { self.it.next().unwrap().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter) { let t: u32 = sc.next(); for _ in 0..t { let n: usize = sc.next(); let mut a: Vec = sc.next_vec(n); let mut ans = "Yes"; while let Some(mut v) = a.pop() { for a in a.iter_mut() { let g = binary_gcd(*a, v); *a /= g; v /= g; } let r = kth_root(v, 2); if r * r != v { ans = "No"; } } writeln!(out, "{}", ans).ok(); } }