use std::collections::HashMap; use proconio::input; fn main() { input! { n:usize, a:[usize;n], } let mut dp = HashMap::new(); dp.insert(0, 1usize); for i in 0..n { let mut dp_next = HashMap::new(); for (&g, &dp_g) in dp.iter() { if g == 0 { *dp_next.entry(a[i]).or_insert(0) += dp_g; } else { *dp_next.entry(gcd(g, a[i])).or_insert(0) += dp_g; } *dp_next.entry(g).or_insert(0) += dp_g; } dp = dp_next; // println!("{:?}",dp); } let ans = *dp.get(&1).unwrap_or(&0); println!("{}", ans); } use math::*; mod math { #[allow(dead_code)] pub fn pow(mut n: usize, mut e: usize, m: usize) -> usize { let mut res = 1; n %= m; while 0 < e { if e & 1 != 0 { res *= n; res %= m; } n *= n; n %= m; e >>= 1; } res } #[allow(dead_code)] pub fn gcd(a: usize, b: usize) -> usize { if b == 0 { a } else { gcd(b, a % b) } } #[allow(dead_code)] pub fn lcm(a: usize, b: usize) -> usize { a / gcd(a, b) * b } #[allow(dead_code)] pub fn prime_factor(mut n: usize) -> std::collections::HashMap { let mut pfacs = std::collections::HashMap::new(); for d in 2.. { if d * d > n { break; } while n % d == 0 { *pfacs.entry(d).or_insert(0) += 1; n /= d; } } if n != 1 { *pfacs.entry(n).or_insert(0) += 1; } pfacs } #[allow(dead_code)] pub fn divisors(n: usize) -> Vec { let mut divs = vec![]; for d in (1..).take_while(|&d| d * d <= n) { if n % d == 0 { divs.push(d); if n / d != d { divs.push(n / d); } } } divs } #[allow(dead_code)] pub fn eratosthenes_sieve(n: usize) -> Vec { let mut is_primes = vec![true; n + 1]; is_primes[0] = false; is_primes[1] = false; let mut primes = vec![]; for i in 2..=n { if !is_primes[i] { continue; } for j in (2 * i..=n).step_by(i) { is_primes[j] = false; } } for (val, is_prime) in is_primes.into_iter().enumerate() { if is_prime { primes.push(val); } } primes } #[allow(dead_code)] pub fn base_n(mut base10: usize, base: usize, len: usize) -> Vec { let mut base_n = vec![]; for _ in 0..len { base_n.push(base10 % base); base10 /= base; } base_n.reverse(); base_n } #[allow(dead_code)] pub fn div_floor(mut a: i64, mut b: i64) -> i64 { if b < 0 { a = -a; b = -b; } if a >= 0 { a / b } else { (a + 1) / b - 1 } } #[allow(dead_code)] pub fn div_ceil(mut a: i64, mut b: i64) -> i64 { if b < 0 { a = -a; b = -b; } if a > 0 { (a - 1) / b + 1 } else { a / b } } }