X_MAX = 10000000 n = gets.to_i x = gets.split.map(&:to_i) dp = Array.new(X_MAX+1){0} x.each{|i| dp[i] = 1} ans = 0 (1..X_MAX).each{|i| if (dp[i] <= 0) then next end (i*2..X_MAX).step(i).each{|j| if (dp[j] >= 1) then dp[j] = [dp[j],dp[i]+1].max end } ans = [ans,dp[i]].max } p ans