#ifndef hari64 #include // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #define debug(...) #else #include "util/viewer.hpp" #define debug(...) viewer::_debug(__LINE__, #__VA_ARGS__, __VA_ARGS__) #endif using namespace std; constexpr int INF = 1001001001; constexpr long long INFll = 1001001001001001001; template bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template vector divisors(T n) { vector ret; for (T i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector As(N); map> m; for (int i = 0; i < N; i++) { cin >> As[i]; m[As[i]].push_back(i); } vector> adj(N); for (int i = 0; i < N; i++) { for (auto& d : divisors(As[i])) { for (auto& ni : m[d]) { if (ni < i) { adj[ni].push_back(i); } } } } debug(adj); vector dp(N, 1); for (int i = 0; i < N; i++) { for (auto& j : adj[i]) { chmax(dp[j], dp[i] + 1); } } debug(dp); cout << *max_element(dp.begin(), dp.end()) << endl; return 0; }