#include #include #include #include using namespace std; int N; int isprime[20010]; int dp[20010]; void eratos(int m) { for (int i = 0; i <= m; i++) isprime[i] = true; isprime[0] = isprime[1] = false; for (int i = 2; i <= m; ++i) { if (isprime[i]) { for (int j = 2 * i; j <= m; j += i) isprime[j] = false; } } } int main() { cin >> N; eratos(N); vector prime; for(int i = 2; i < N + 1; i++) { if(isprime[i]) prime.push_back(i); } memset(dp, -1, sizeof(dp)); dp[0] = 0; for (int u : prime) { for (int j = 0; j <= N; j++) { dp[j + 1] = max(dp[j], dp[j - u] + 1); } } cout << dp[N] << endl; return 0; }