macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { #[allow(unused_mut)] let mut 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_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { #[allow(non_snake_case)] #[allow(unused_mut)] let mut $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } 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") }; } #[allow(unused_macros)] macro_rules! debug { ($($a:expr),*) => { eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*); } } fn gcd(mut x: u32, mut y: u32) -> u32 { let mut t = 0; while y != 0 { t = x % y; x = y; y = t; } x } use std::cmp; fn divisor(n: u32) -> Vec { let mut ret = Vec::new(); let sqrtn = (n as f64).sqrt() as u32; for i in 1..sqrtn + 1 { if n % i == 0 { ret.push(i); if i * i != n { ret.push(n / i); } } } ret.sort(); ret } fn main() { input! { n: usize, arr: [usize; n], } arr.sort(); let mut dp = vec![0; 1_000_100]; for x in &arr { dp[*x] = 1; } for i in 1..1_000_001 { if dp[i as usize] != 0 { let divisors = divisor(i); for d in divisors { if d != i { dp[i as usize] = cmp::max(dp[i as usize], dp[d as usize] + 1) } } } } let mut ans = 0; for x in &arr { ans = cmp::max(ans, dp[*x]); } println!("{}", ans); }