#include #include #include #include #include #include using namespace std; typedef pair P; typedef unsigned long long ll; const int inf = 999999999; const int mod = 1000000007; vector eratosthenes(int n){ bool arr[n]; for(int i = 0; i <= n; i++){ arr[i] = true; } arr[0] = false; arr[1] = false; for(int i = 2; i * i <= n; i++){ if(arr[i]){ for(int j = i * 2; j <= n; j += i){ arr[j] = false; } } } vector primes; for(int i = 0; i <= n; i++){ if(arr[i]) primes.push_back(i); } return primes; } int main(){ int n; cin >> n; vector primes = eratosthenes(n); vector dp(n + 1, -1); dp[0] = 0; for(int k = 0; k < primes.size(); k++){ int p = primes[k]; for(int i = n; i >= 0; i--){ if(i + p < n + 1 && dp[i] != -1){ dp[i + p] = max(dp[i + p], dp[i] + 1); } } } cout << dp[n] << endl; return 0; }