#include #include #include #include #include using namespace std; int N; int dp[20001][20001]; int idx = 0; bool is_prime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } int main(void) { cin >> N; ++dp[idx][2]; for (int i = 3; i <= N; ++i) { if (is_prime(i)) { ++idx; for (int j = 0; j <= N; ++j) { if (dp[idx - 1][j] != 0) { dp[idx][j] = dp[idx - 1][j]; dp[idx][j + i] = max(dp[idx][j + i], dp[idx - 1][j] + 1); } } dp[idx][i] = max(dp[idx][i], 1); } } if (dp[idx][N] == 0) dp[idx][N] = -1; cout << dp[idx][N] << endl; return 0; }