#include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int MAX_N = 1e5 + 10; int min_factor[MAX_N] = {}; struct init_prime { init_prime() { min_factor[1] = -1; for (int i = 2; i < MAX_N; i++) { if (min_factor[i] != 0) continue; for (int j = i + i; j < MAX_N; j += i) min_factor[j] = i; } } } init_prime; void factorization(int n, unordered_map &res) { if (n <= 1) return; if (!min_factor[n]) { ++res[n]; return; } ++res[min_factor[n]]; factorization(n / min_factor[n], res); } void dfs(unordered_map::iterator itr, int prod, unordered_map &mp, vector &res) { if (itr == mp.end()) { res.emplace_back(prod); return; } auto [p, e] = *itr; for (int i = 0; i <= e; i++) { dfs(next(itr), prod, mp, res); prod *= p; } } vector divisors(int n) { unordered_map mp; factorization(n, mp); vector res; dfs(mp.begin(), 1, mp, res); return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (auto &&t : a) cin >> t; vector dp(100010, 0); for (int i = 0; i < n; i++) { int Max = 0; vector ds = divisors(a[i]); for (auto d : ds) chmax(Max, dp[d]); dp[a[i]] = Max + 1; } cout << *max_element(begin(dp), end(dp)) << "\n"; }