#include #include using namespace std; // エラトステネスの篩 O(nloglogn) // create p (1<=p<=n and p is a prime nubmer) #define MAX_N 100000 vector prime; bool is_prime[MAX_N + 1]; long long sieve(long long n) { long long p = 0; for (long long i = 0; i <= n; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (long long i = 2; i <= n; i++) { if (!is_prime[i]) continue; prime.push_back(i); for (long long j = 2 * i; j <= n; j += i) { is_prime[j] = false; } } return p; } int dp1[3000][21000]; void solve1(int N) { for (int i = 0; i < 3000; i++) { for (int j = 0; j < 21000; j++) { dp1[i][j] = -1; } } dp1[0][0] = 0; for (int i = 0; i < prime.size(); i++) { for (int j = 0; j <= N; j++) { if (dp1[i][j] < 0) continue; dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j]); if (j + prime[i] > N) continue; dp1[i + 1][j + prime[i]] = max(dp1[i + 1][j + prime[i]], dp1[i][j] + 1); } } } int dp2[3000][21000]; void solve2(int N) { for (int i = 0; i < 3000; i++) { for (int j = 0; j < 21000; j++) { dp2[i][j] = -1; } } dp2[0][0] = 0; for (int i = 0; i < prime.size(); i++) { for (int j = 0; j <= N; j++) { if (dp2[i][j] < 0) continue; dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i][j]); dp2[i + 1][j + prime[i]] = max(dp2[i + 1][j + prime[i]], dp2[i][j] + 1); } } } int main() { sieve(20000); solve1(20000); solve2(20000); int N; cin >> N; cout << dp1[prime.size()][N] << endl; //for (int i = 10000; i <= 20000; i++) { // int a1 = dp1[prime.size()][i]; // int a2 = dp2[prime.size()][i]; // cout << i << ' ' << a1 << ' ' << a2 << endl; // if (a1 != a2) { // return 0; // } //} return 0; }