#include #include using namespace std; using vi = vector; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) templatebool chmax(T &a,const T &b){if(a> N; rep(i, N+1) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (int i = 2; i * i <= N; ++i) { if (!is_prime[i]) continue; for (int j = i*i; j <= N; j += i) is_prime[j] = false; } vi prime; rep(i, N+1) if (is_prime[i]) prime.push_back(i); rep(i, 3000) rep(w, N+1) dp[i][w] = w == 0 ? 0 : -1; rep(i, prime.size()) rep(w, N+1) { dp[i+1][w] = dp[i][w]; if (w-prime[i] >= 0 && dp[i][w-prime[i]] >= 0) dp[i+1][w] = max(dp[i+1][w], dp[i][w-prime[i]]+1); } cout << dp[prime.size()][N] << endl; }