#include #include #include #include int main() { using usize = std::size_t; const auto chmin = [](usize &a, const usize b) { if (b < a) { a = b; } }; static constexpr usize ALim = 300001; std::vector prime; { std::vector sieve(ALim, true); for (usize i = 2; i != ALim; ++i) { if (sieve[i]) { prime.push_back(i); for (usize j = i; j < ALim; j += i) { sieve[j] = false; } } } } usize n; std::cin >> n; std::vector> rev(ALim); std::vector dp(ALim, n); for (usize i = 0; i != n; ++i) { usize a; std::cin >> a; rev[a].push_back(i); chmin(dp[a], i); } usize len = 0; while (std::any_of(dp.cbegin(), dp.cend(), [n](usize x) { return x < n; })) { ++len; std::vector exc(ALim, n); for (const usize p : prime) { for (usize i = 1; i * p < ALim; ++i) { chmin(dp[i * p], dp[i]); chmin(exc[i * p], dp[i]); } } for (usize i = 1; i != ALim; ++i) { usize j = 0; const usize size = rev[i].size(); while (j != size && rev[i][j] <= exc[i]) { ++j; } if (j == size) { dp[i] = n; } else { dp[i] = rev[i][j]; } } } std::cout << len << std::endl; }