#include using namespace std; #define rep(i, j, n) for(int i=j;i pi; template using vt = vector; template using vvt = vector>; i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));} i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);} int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; bool PrimeNumber(int n) { if(n < 2) return false; for(int i = 2; i * i <= n; ++i) { if(n % i == 0) return false; } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vt vec; rep(i, 2, n + 1) { if(PrimeNumber(i)) vec.push_back(i); } int sz = vec.size(); vvt dp(sz + 1, vt(n + 1, -1)); dp[0][0] = 0; rep(i, 0, sz) { rep(j, 0, n + 1) { dp[i + 1][j] = dp[i][j]; if(j >= vec[i]) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - vec[i]] + 1); } } if(dp[sz][n] == 0) cout << -1 << endl; else cout << dp[sz][n] << endl; }