#include using namespace std; auto chmax = [](auto&& l, auto r) { return l < r ? l = r, 1 : 0; }; constexpr int lim = 3e5, th = 512; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for_each(begin(a), end(a), [](int& e) { cin >> e; }); reverse(begin(a), end(a)); vector> ds(lim + 1); for (int d = 1; d < th; ++d) { for (int i = 2 * d; i <= lim; i += d) { ds[i].push_back(d); } } vector dp(lim + 1), m(th); for (int e : a) { int mx = -1; if (e < th) { mx = m[e]; } else { for (int i = 2 * e; i <= lim; i += e) { chmax(mx, dp[i]); } } chmax(dp[e], mx + 1); for (int d : ds[e]) { chmax(m[d], dp[e]); } } cout << *max_element(begin(dp), end(dp)) << '\n'; }