#include #include #include #include #include using namespace std; int N; vector dp; vector primes; 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; } void set_prime() { for (int i = 0; i <= N; ++i) { if (is_prime(i)) { primes.push_back(i); } } } int main(void) { cin >> N; set_prime(); dp.resize(N + 1, -1); dp[0] = 0; for (size_t p_idx = 0U; p_idx < primes.size(); ++p_idx) { int p = primes[p_idx]; for (int n = N; n >= 0; --n) { if (n + p < N + 1 && dp[n] != -1) { dp[n + p] = max(dp[n + p], dp[n] + 1); } } } cout << dp[N] << endl; return 0; }