#include #include #include using namespace std; #define rep(i,x) for(int i=0;i<(x);++i) #define rep1(i,x) for(int i=1;i<=(x);++i) const int inf = 1e9; bool is_prime[10001]; int dp[10001]; int M, N, C[21]; void sieve() { fill(is_prime, is_prime + 10001, true); is_prime[0] = is_prime[1] = false; for (int i = 2; i <= 10000; ++i) { if (!is_prime[i]) continue; is_prime[i] = true; for (int j = i * 2; j <= 10000; j += i) { is_prime[j] = false; } } } signed main() { cin >> M >> N; rep(i, N) cin >> C[i]; sort(C, C + N); sieve(); fill(dp, dp + 10001, -1); dp[0] = 0; rep(i, N) { for (int j = C[i]; j <= M; ++j) { if (~dp[j - C[i]]) { dp[j] = max(dp[j], dp[j - C[i]] + 1); } } } int ans = *max_element(dp, dp + 10001); for (int i = M - 1; i >= 0; --i) { if (is_prime[i] && ~dp[M - i]) { ans += dp[M - i]; } } cout << ans << endl; }