mod math { pub fn prime_factorize(mut n: u16) -> Vec { let mut res = Vec::new(); for i in 2.. { if i * i > n { break; } while n % i == 0 { res.push(i); n /= i; } } if n > 1 { res.push(n); } res } } fn run<'a, I, W>(mut scanner: I, mut writer: W) where I: Iterator, W: std::io::Write, { macro_rules! scan { ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::>()); (($($t:tt),*)) => (($(scan!($t)),*)); (Usize1) => (scan!(usize) - 1); (Bytes) => (scan!(String).into_bytes()); ($t:ty) => (scanner.next().unwrap().parse::<$t>().unwrap()); } macro_rules! input { ($($($v:ident)* : $t:tt),* $(,)?) => ($(let $($v)* = scan!($t);)*); } macro_rules! println { ($($arg:tt)*) => (writeln!(writer, $($arg)*).ok()); } input! { n: usize, k: u32, a: [u16; n], } let d = a.iter().map(|&a| math::prime_factorize(a)).collect::>(); let mut set = std::collections::BTreeSet::new(); for bit in 0u32..1 << n { if bit.count_ones() < k { continue; } let mut sum = 0; let mut product = Vec::new(); for (i, (a, ref mut d)) in a.iter().zip(d.iter().cloned()).enumerate() { if bit >> i & 1 == 1 { sum += a; product.append(d); } } product.sort(); set.insert(math::prime_factorize(sum)); set.insert(product); } let ans = set.len(); println!("{}", ans); } fn main() { let ref mut buf = Vec::new(); std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok(); let scanner = unsafe { std::str::from_utf8_unchecked(buf).split_ascii_whitespace() }; let stdout = std::io::stdout(); let writer = std::io::BufWriter::new(stdout.lock()); run(scanner, writer); }