#include #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(obj) (obj).begin(),(obj).end() #define debug(var) do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0) template void view(T e){std::cout << e << std::endl;} template void view(const std::vector& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template void view(const std::vector >& vv){ for(const auto& v : vv){ view(v); } } using namespace std; using ll = long long; using vi = vector; using vl = vector; using vvi = vector>; using vvl = vector>; struct SieveOfEstosthenes { int n; vector is_prime; vector prime; SieveOfEstosthenes(int n) : n(n), is_prime(n, true) { is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; ++i) { if (is_prime[i]) { prime.push_back(i); for (int j = 2 * i; j <= n; j += i) is_prime[j] = false; } } } }; void Main() { int N; cin >> N; SieveOfEstosthenes era(N); vi prime = era.prime; vvi dp(prime.size() + 1, vi(N + 1, -1)); dp[0][0] = 0; REP(i, prime.size()) { REP(j, N + 1) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if (j >= prime[i] && dp[i][j - prime[i]] != -1) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - prime[i]] + 1); } } } cout << dp[prime.size()][N] << endl; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }