use std::io::Read; use std::collections::{HashMap, BinaryHeap}; use std::cmp::{max, min}; fn gcd(a: usize, b: usize) -> usize { if a % b == 0 { return b; } gcd(b, a % b) } fn main() { let mut all_data = String::new(); std::io::stdin().read_to_string(&mut all_data).ok(); let all_data: Vec<&str> = all_data.trim().split('\n').map(|s| s.trim()).collect(); let a: Vec = all_data.iter().skip(1).next().unwrap().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut keys: BinaryHeap = BinaryHeap::new(); let mut gcd2count: HashMap = HashMap::new(); for val in a { let mut temp_keys = keys.clone().to_owned(); for _ in 0..keys.len() { let key = keys.pop().map(|s| (s as isize) * -1).unwrap() as usize; let count = *gcd2count.get(&key).unwrap(); let next_key = gcd(max(key, val), min(key, val)); if let Some(x) = gcd2count.get_mut(&next_key) { *x += count; } else { gcd2count.insert(next_key, count); temp_keys.push(-(next_key as isize)); } } if let Some(x) = gcd2count.get_mut(&val) { *x += 1; } else { gcd2count.insert(val, 1); temp_keys.push(-(val as isize)); } keys = temp_keys; } println!("{}", gcd2count.get(&1usize).unwrap_or(&0usize)); }