#include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr ll TEN(int n) { return (!n) ? 1 : 10 * TEN(n-1); } int m, n, c[20]; int dp0[10100], dp1[10100]; bool us0[10100], us1[10100]; int dfs(int x) { if (x < 0) return -100000; if (x == 0) return 0; if (us0[x]) return dp0[x]; us0[x] = true; int ans = -100000; for (int i = 0; i < n; i++) { ans = max(ans, 1+dfs(x-c[i])); } return dp0[x] = ans; } int dfs2(int x) { if (x < 0) return -100000; if (x == 0) return 0; if (us1[x]) return dp1[x]; us1[x] = true; int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, 1+dfs2(x-c[i])); } return dp1[x] = ans; } int main() { cin >> m; cin >> n; for (int i = 0; i < n; i++) { cin >> c[i]; } int ans = dfs2(m); for (int i = 2; i < m; i++) { bool f = true; for (int j = 2; j*j <= i; j++) { if (i % j == 0) f = false; } if (f) { ans += max(0, dfs(m-i)); } } cout << ans << endl; return 0; }