#![allow(non_snake_case)] #![allow(unused_imports)] //use itertools::itertools; //use proconio::input; //use proconio::marker::*; use std::cmp::Reverse; use std::collections::*; fn main() { input! { n:usize, a:[usize;n], } let m = *a.iter().max().unwrap(); let mut dp = vec![0; m + 1]; for i in 0..n { let divs = divisors(a[i]); for div in divs { if div == a[i] { continue; } dp[a[i]] = dp[a[i]].max(dp[div] + 1); } if dp[a[i]] == 0 { dp[a[i]] = 1; } } let ans = *dp.iter().max().unwrap(); println!("{}", ans); } use math::*; mod math{ use std::collections::HashMap; #[allow(dead_code)] pub fn pow(mut n: usize, mut e: usize, m: usize) -> usize { let mut res = 1; 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) -> HashMap { let mut pfacs = 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 } } mod input { #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } }