#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]; bool used[10001]; bool can_make[10001]; int memo[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; } } } int calc(int a) { int& res = memo[a]; if (a == 0) return 0; if (~res) return res; res = -inf; rep(i, N) { if (a - C[i] < 0) break; res = max(res, 1 + calc(a - C[i])); } return res; } signed main() { cin >> M >> N; rep(i, N) cin >> C[i]; sort(C, C + N); sieve(); fill(memo, memo + 10001, -1); can_make[0] = true; for (int i = 0; i < N; ++i) { for (int j = C[i]; j <= M; ++j) { can_make[j] = can_make[j] || can_make[j - C[i]]; } } rep(i, M + 1) memo[i] = calc(i); int ans = 0; for (int i = M; i >= 0; --i) { if (is_prime[i] && can_make[M - i]) { ans += calc(M - i); } } ans += *max_element(memo, memo + 10001); cout << ans << endl; }