#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct Eratosthenes { vector isp,minfactor,myprime,moebius; Eratosthenes (int n) : isp(n+1,1),minfactor(n+1,__INT_MAX__),moebius(n+1,1){ isp[0] = isp[1] = 0; minfactor[0] = 0;minfactor[1] = 1; for(int p = 2;p <= n;p++){ if(!isp[p]) continue; minfactor[p] = p; moebius[p] = -1; myprime.push_back(p); for(int q = 2*p;q <= n;q += p){ isp[q] = false; if(!((q/p)%p)) moebius[q] = 0; else moebius[q] = -moebius[q]; minfactor[q] = min(minfactor[q],p); } } } vector> prime_factorize(int n) { vector> res; while(n-1){ int p = minfactor[n]; int exp = 0; while(minfactor[n] == p){ n /= p; exp ++; } res.push_back(make_pair(p,exp)); } return res; } vector divisors(int n){ vector res; res.push_back(1); auto pf = prime_factorize(n); for(auto [p,e]:pf){ int s = (int)res.size(); for(int i = 0;i < s;i++){ int v = 1; for(int j = 0;j < e;j++){ v *= p; res.push_back(res[i]*v); } } } return res; } }; Eratosthenes er((int)3e5); int N,A[3 << 17],dp[3 << 17]; void solve() { cin >> N; for(int i = 0;i < N;i++) { cin >> A[i]; dp[A[i]] = max(dp[A[i]],1); for(int D:er.divisors(A[i]))if(D < A[i]) dp[A[i]] = max(dp[A[i]],dp[D]+1); } int ans = 0; for(int i = 0;i < N;i++) ans = max(ans,dp[A[i]]); cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; //cin >> tt; while(tt--) solve(); }