#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i)) #define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i)) #define REP(i, n) FOR(i, 0, n) #define rREP(i, n) rFOR(i, 0, (n-1)) #define SORT(A) std::sort((A).begin(), (A).end()) #define ALL(A) (A).begin(), (A).end() // 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A) #define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end()) using lli = long long int; using pii = std::pair; // グリッド上の縦横移動 constexpr std::array, 4> dxdy = { std::pair( 1, 0), std::pair(-1, 0), std::pair( 0, 1), std::pair( 0, -1) }; void VintOut(std::vector& A){ const int n = A.size(); if(n == 0){putchar('\n'); return;} printf("%d", A[0]); for(int i = 1; i < n; ++i) printf(" %d", A[i]); putchar('\n'); } void VintOut(std::vector& A){ const int n = A.size(); if(n == 0){ putchar('\n'); return;} printf("%lld", A[0]); for(int i = 1; i < n; ++i) printf(" %lld", A[i]); putchar('\n'); } template inline bool chmin(T& a, T b){ if(b < a){ a = b; return true;} return false; } template inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false; } inline bool isIn(int x, int y, int H, int W){ return 0 <= x and x < H and 0 <= y and y < W; } inline bool bitUP(int state, int k){ return (state >> k) & 1; } inline bool bitUP(long long int state, int k){ return (state >> k) & 1;} // z-algorithm template std::vector z_algorithm(const T &str) { const int n = str.size(); std::vector resOfCP(n); resOfCP[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n and str[j] == str[i + j]) ++j; resOfCP[i] = j; if (j == 0) { ++i; continue;} int k = 1; while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k; i += k; j -= k; } return resOfCP; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ constexpr int MAX_N = 3e5; constexpr int MAX_A = 3e5; std::array A; std::array, MAX_A> D; std::array Len; std::array Min; int main(void){ int n; scanf("%d", &n); for(int i = 0; i < n; ++i){ int a; scanf("%d", &a); D[a].push_back(i); A[i] = a; } for(int x = 1; x <= MAX_A; ++x) Min[x] = -1, Len[x] = (D[x].size() > 0) ? 1 : 0; int res = 0; for(int i = 0; i < n; ++i){ int j = A[i]; if(res < Len[j]) res = Len[j]; auto itr = std::upper_bound(D[j].begin(), D[j].end(), Min[j]); if(itr == D[j].end() or (*itr != i)) continue; for(int k = 2 * j; k <= MAX_A; k += j) if(D[k].size() > 0){ if(Len[k] < Len[j] + 1){ Len[k] = Len[j] + 1; Min[k] = i; } } } printf("%d\n", res); return 0; }