#include #include #include #include #include #include using namespace std; bool Prime[10001]; int Num[20001]; int main() { for (int i = 0; i < 10001; i++)Prime[i] = true; Prime[0] = false; Prime[1] = false; for (int i = 2; i < 10001; i++) { if (Prime[i]) { for (int j = i * 2; j < 10001; j += i) { Prime[j] = false; } } } int m, n; cin >> m >> n; vectorC; for (int i = 0; i < n; i++) { int c; cin >> c; if (c <= m)C.push_back(c); } for (int j = 0; j < C.size(); j++)Num[C[j]] = 1; for (int i = 0; i < m; i++) { for (int j = 0; j < C.size(); j++) { if (Num[i] == 0)continue; Num[i + C[j]] = max(Num[i] + 1, Num[i + C[j]]); } } int sum = 0; int maxcnt = 0; for (int i = 0; i <= m; i++) { maxcnt = max(maxcnt, Num[i]); } for (int i = 0; i < m; i++) { if (Prime[m - i]) { sum += Num[i]; } } cout << sum + maxcnt << endl; return 0; }