#include #include #include #include #include #include namespace nono { class EratosthenesSieve { public: EratosthenesSieve(const int n) : n_(n), sieve_(n + 1) { std::iota(sieve_.begin(), sieve_.end(), 0); sieve_[0] = -1; sieve_[1] = -1; for (long long i = 2; i * i <= n_; ++i) { if (sieve_[i] == i) { for (long long j = i * i; j <= n_; j += i) { if (sieve_[j] == j) { sieve_[j] = i; } } } } } std::vector enumerate_primes() const { std::vector primes; for (int i = 2; i <= n_; i++) { if (sieve_[i] == i) { primes.push_back(i); } } return primes; } bool is_prime(const int v) const { return sieve_[v] == v; } std::vector> factorize(long long v) const { std::vector> factor; while (v > 1) { int count = 0; int prime = sieve_[v]; while (prime == sieve_[v]) { count++; v /= sieve_[v]; } factor.emplace_back(prime, count); } return factor; } std::vector enumerate_divisors(int v) const { std::vector divisors; const std::vector> factors = factorize(v); auto dfs = [&](auto self, const int i, int value) { if (i == factors.size()) { divisors.push_back(value); return; } for (int j = 0; j <= factors[i].second; j++) { self(self, i + 1, value); value *= factors[i].first; } }; dfs(dfs, 0, 1); return divisors; } int operator[](const int v) const { return sieve_[v]; } private: const int n_; std::vector sieve_; }; } // namespace nono int main() { const int MAX = 1e5; nono::EratosthenesSieve sieve(MAX); int n; std::cin >> n; std::vector a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::vector max(MAX + 1); for (int i = n - 1; i >= 0; i--) { int ans = max[a[i]] + 1; for (const int divisor: sieve.enumerate_divisors(a[i])) { max[divisor] = std::max(max[divisor], ans); } } std::cout << max[1] << '\n'; }