#include #include #include #include #include #include using namespace std; #define loop(i,n) for(int i = 0; i < (n); i++) #define loops(i,f,n) for(int i = (f); i < (n); i++) #define VEC vector #define INF INT_MAX #define debug(a) cout< v (n, VEC(n)) //loop(i,n)loop(j,n)dp[i][j]=-1; vector P; void makeprimes(int n) { vector primes; primes.resize(n + 1, true); primes[0] = primes[1] = false; loops(i, 2, sqrt(n)) if (primes[i]) for (int j = 0; i * (j + 2) < n; j++) primes[i * (j + 2)] = false; loops(i, 2, n + 1) if (primes[i]) P.push_back(i); } int main() { int n; cin >> n; makeprimes(n + 1); vectordp(3010, VEC(40101)); loop(i, 3010)loop(j, 20101)dp[i][j] = -1; dp[0][0] = 0; loop(i, P.size()) { loop(j, n+1) { if (dp[i][j] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j + P[i]] = max(dp[i + 1][j + P[i]], dp[i][j] + 1); } } } printf("%d\n", dp[P.size()][n]); return 0; }