#include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x) using namespace std; template void setmax(T & a, T const & b) { if (a < b) a = b; } int main() { // input int n; scanf("%d", &n); vector xs(n); repeat (i,n) scanf("%d", &xs[i]); // compute int l = *whole(max_element, xs); vector exists(l+1); for (int x : xs) exists[x] = true; vector dp(l+1); whole(sort, xs); whole(reverse, xs); int ans = 0; for (int x : xs) { for (int y = x; y < l+1; y += x) { if (exists[y]) { setmax(dp[x], dp[y] + 1); } } setmax(ans, dp[x]); } // output printf("%d\n", ans); return 0; }