#include #include #include #include using namespace std; vector prime_table(int n) { vector is_prime(n + 1); if (n) iota(is_prime.begin() + 2, is_prime.end(), 2); for (int i = 2; i * i <= n; i++) if (is_prime[i]) { for (int j = i + i; j <= n; j += i) is_prime[j] = 0; } return is_prime; } vector make_primes(int ma) { vector ps = prime_table(ma); ps.erase(remove(ps.begin(), ps.end(), 0), ps.end()); return ps; } int main() { int n; cin >> n; vector dp(n + 1, -1); dp[0] = 0; for (int p: make_primes(n)) { for (int i = n; i >= p; i--) if (dp[i - p] == -1) { dp[i] = max(dp[i], dp[i - p] + 1); } } cout << dp.back() << endl; return 0; }